[英]use xpath for extracting text after <br/> tag
I have the next HTML.我有下一个 HTML。 I want to extract the name with xpath, in my case is Steve.
我想用 xpath 提取名称,在我的例子中是 Steve。 I use Selenium Python.
我使用硒 Python。 How can i do it?
我该怎么做?
<section class="PersonalCard">
<!--<h2></h2>-->
<div class="clr" style="height:25px"/>
<span>Speciality:</span>
<br/>
Steve
<div class="clr" style="height:40px"/>
<h3>Details</h3>
<table cellspacing="0" cellpadding="0" border="0">
<div class="clr" style="height:40px"/>
<div class="clr">
</section>
You can use below way to get the text by executing javascript您可以使用以下方式通过执行 javascript 来获取文本
element = driver.find_element_by_xpath("//section[@class='PersonalCard']/div[@class='clr']")
print(driver.execute_script("return arguments[0].childNodes[4].textContent", element).strip())
您是否为此 xpath 尝试过类似的操作:
el = driver.find_element_by_xpath('//div[@class="clr"]/span/br')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.