I am currently trying to get the href
out of the following web page structure:
<div style="something> # THIS IS THE MAIN DIV I CAN GET
<div class="aegieogji"> # First ROW sub-div under the main div
<div class="aegegaegeg"> # SUB-SUB-DIV
<a class=egaiegeigaegeigaegge", href="link_I_need">Text</a> # First HREF
<div class="eagegeg"> # SUB-SUB-DIV
<a class=egaegegaegaeg", href="link_I_need">Text</a> # Second HREF
<div class="agaeheahrhrahrhr"> # SUB-SUB-DIV
<a class=arhrharhrahrah", href="link_I_need">Text</a> # Third HREF
<div class="argagragragaw"> # Second ROW subdiv under the main div
<div class="aarhrahrah"> # SUB=SUB-DIV
<a class=arhahrhahr", href="link_I_need">Text</a> # First HREF
<div class="ahrrahrae"> # SUB-SUB-DIV
<a class=eagregargreg", href="link_I_need">Text</a> # Second HREF
<div class="ergrgegaegr"> # SUB-SUB-DIV
<a class=aegaegregrege", href="link_I_need">Text</a> # Third HREF
...
...
</div>
Using Python Selenium and ChromeDriver I can read the main div "something"
:
main_elem = browser.find_element(By.XPATH, "/html/body/div[2]/div/div/div/div[1]/div/div/div/div[1]/div[1]/div[2]/section/main/article/div[2]/div/div[1]")
Now, from here I am struggling using correctly Selenium to get all the links under href
for all the sub-sub-div.
Do you have any idea on how I can easily get those? Thank you
PS: I can see that the first sub-sub-div has the following xpath:
/html/body/div[2]/div/div/div/div[1]/div/div/div/div[1]/div[1]/div[2]/section/main/article/div[2]/div/div[1]/div[1]
Then the second:
/html/body/div[2]/div/div/div/div[1]/div/div/div/div[1]/div[1]/div[2]/section/main/article/div[2]/div/div[1]/div[2]
and so on while the second row sub-sub-div xpath
is:
/html/body/div[2]/div/div/div/div[1]/div/div/div/div[1]/div[1]/div[2]/section/main/article/div[2]/div/div[2]/div[1]
so there's div[2]
rather div[1]
and so on.