<div class="someclass">
<p class="name"><a href="#/word/1/">helloworld</a></p>
</div>
//我想使用 python selenium 代码从 anchor 标记打印 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")
我希望这有帮助,如果没有请告诉我:)
关于python-3.x - 我想使用 selenium python 从 anchor 标记获取文本我想打印文本 helloworld,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43797457/