我尝试了几种不同的选择:
dneyot=driver.find_elements_by_xpath("//*[starts-with(@id, 'popover-')]/text()")
dneyot=driver.find_elements_by_xpath("//*[starts-with(@id, 'popover-')]/b[1]/text()")
我的代码:
^{pr2}$升级版: 我使用以下工具在浏览器中找到我需要的项目:
//*[starts-with(@id, 'popover-')]/text()[1]
但会出错
selenium.common.exceptions.InvalidSelectorException:
Message: invalid selector: The result of the xpath expression "//*[starts-with(@id, 'popover-')]/text()[1]" is: [object Text]. It should be an element.
如果要获取不包括
<b>
节点文本的文本,则需要使用以下XPath:它将标识div节点,然后通过使用
^{pr2}$find_elements_by_xpath()
方法,您可以从div node检索所有文本。请尝试以下代码:更新:
我怀疑,上述方法可能不起作用,我们可能无法使用常规方法识别/获取数据-在这种情况下,您需要使用JavaScriptExecutor来获取如下数据:
由于您的网站是用英语以外的其他语言编写的,您可能无法打印/获取一些数据。在
要获取特定的子节点数据,需要执行以下操作:
^{4}$我希望它能帮助。。。在
find_elements_by_xpath()
返回一个webelement-selenium实际使用的基本对象。xpath以
/text()
结尾,它将返回xml文档中节点的文本内容,而不是selenium期望的对象。因此,只需将其更改为不具有后缀-这将返回元素本身,并通过在Python中调用.text
获得其(元素的)文本:使用Beautifulsoup:
在父项}。在
div
内找到div
,其中包含{相关问题 更多 >
编程相关推荐