I have the next HTML. I want to extract the name with xpath, in my case is Steve. I use Selenium 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
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')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.