python-3.x - 我想使用 selenium python 从 anchor 标记获取文本我想打印文本 helloworld

标签 python-3.x selenium

<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/

相关文章:

java - 无法从 Booking.com 的搜索结果中获取价格

python-3.x - 无法在 Google TPU 中导入 python 包 jax

python-3.x - 在 python 3 中请求 HTTP/2 切换协议(protocol)

python-3.x - 从 Python 2 加载 Python 3 pickle

c# - Selenium Webdriver + PhantomJS 保持在大约 :blank for a specific site

php - 如何在 PHPUnit 测试中启动 InternetExplorerDriver

java - 如何在 Selenium Web 驱动程序中编写等待,直到下拉列表中的值被填充,然后单击按钮

Python 一行 if 语句有两个 Action

python - Pandas:应用一个以列和变量作为参数的函数

google-chrome - Selenium ChromeDriver - 如何作为守护进程运行和部署?