I am trying to write a program that writes code for me. Imagine that I have a <ul>
list on a website and I need to scrape all the xpath selectors for each element on that list. Is there an easy way to tell python to grab the xpath selectors for all of the elements in the <ul>
?
For example we have this <ul>
:
<ul id="test">
<li><a href="#">Zurich</a></li>
<li><a href="#">Geneva</a></li>
<li><a href="#">Winterthur</a></li>
<li><a href="#">Lausanne</a></li>
<li><a href="#">Lucerne</a></li>
</ul>
And I have this code in python:
ul= driver.find_elements_by_id('test')
for element in ul:
selector = **find the xpath/selector**
text = element.text
How can I scrape the xpath for each link in the <ul>
?