![](/img/trans.png)
[英]Get text from textarea using Python & Selenium Webdriver (no value attribute)
[英]How to get the some text value in this html with Selenium Webdriver using Python?
我如何從下面的html代碼中使用selemiun和python獲取文本值“ This Text 1”和“ This Text 2”:
<p>
<b>Studio:</b>
<a href="http://www.somelink.com/some_page/">This Text 1</a>
" | "
<b>Director:</b> This Text 2
</p>
我已經嘗試過幾種類似的方法:
driver.find_element_by_xpath("//*[contains(text(), 'Director:')]")
但沒有得到結果。
要獲取文本“ This Text 1
和“ This Text 2
請使用以下選項。
獲取xpath
This Text 1
使用以下xpath
print(driver.find_element_by_xpath("//p/b[contains(.,'Studio')]/following::a").text)
使用JavaScript Executor
獲取此文This Text 2
element=driver.execute_script('return arguments[0].lastChild.textContent;', driver.find_element_by_xpath("//p[contains(.,'Director')]"))
print(element.strip())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.