Within my code, I have this odd repetitive HTML structure (with no classes) and I'm looking to extract all links along with the accompanying text below each link.
While it's simple enough to grab all the links using a basic CSS query selector like a
, I also need to retrieve the text located within a sibling element of the ancestor of each link. This requires traversing up through the levels of divs before moving back down again.
Does anyone have any suggestions on how to ascend and then descend using a CSS selector?
...
...
...
<div> <----first level of div
<div> <----second level of div
<span>
<span>
<div> <----third level of div
<a href=""> <----element that I can easily capture
</div>
</span>
</span>
</div>
<div></div>
<div>
<span>
<span>
text to capture <----text I am trying to obtain
</span>
</span>
</div>
<div>
...
...
...