How To Formulate The Xpath Expression From The Following Html
Hi, I would like to write an xpath expression to ONLY print the text for all the 'class - insights type1'. I don't need to print the ones that has 'hide' . Following CSS selecto
Solution 1:
Here's how you can do this:
//div[@class="content"]/div[@class="insights type1"]
In python call find_elements_by_xpath()
and get the text of each div found:
fordivindriver.find_elements_by_xpath('//div[@class="content"]/div[@class="insights type1"]'):
printdiv.text
Note that if you need only one single div, use just find_element_by_xpath()
:
div = driver.find_element_by_xpath('//div[@class="content"]/div[@class="insights type1"]')
print div.text
Also, if these div
s can be outside of content
div
too - use //div[@class="insights type1"]
.
Hope that helps.
Solution 2:
You can use Chrome's Dev Tools for this.
Fire up the dev tools using F12, and just right-click the element whose xpath you want.
Then use lxml to process the xml tree.
Post a Comment for "How To Formulate The Xpath Expression From The Following Html"