<div class="someclass">
<p class="name"><a href="#/word/1/">helloworld</a></p>
</div>
//我想使用python selenium代码打印来自锚标记的helloworld文本。我想从使用硒python的锚标记中获取文本我想要打印文本helloworld
<div class="someclass">
<p class="name"><a href="#/word/1/">helloworld</a></p>
</div>
//我想使用python selenium代码打印来自锚标记的helloworld文本。我想从使用硒python的锚标记中获取文本我想要打印文本helloworld
您可以使用CSS做到这一点:
.find_element_by_css_selector("p.name a")`,
,或者您可以使用XPath做到这一点:
.find_element_by_xpath("//p[@class='name']/a")
例子:
element = self.browser.find_element_by_css_selector("p.name a")
print element.get_attribute("text")
我希望这有助于,如果不告诉我:)
'.text'不会返回锚标记的文本值。这个''element.get_attribute(“text”)' –
谢谢,我更新了答案 – Thomas
你试过了什么?你是否看到任何对你来说很复杂的事情 – NarendraR