Here is the HTML code:
<div id="someid">
<h2>Specific text 1</h2>
<a class="hyperlinks" href="link"> link1 inside specific text 1</a>
<a class="hyperlinks" href="link"> link2 inside specific text 1</a>
<a class="hyperlinks" href="link"> link3 inside specific text 1</a>
<h2>Specific text 2</h2>
<a class="hyperlinks" href="link"> link1 inside specific text 2</a>
<a class="hyperlinks" href="link"> link2 inside specific text 2</a>
<a class="hyperlinks" href="link"> link3 inside specific text 2</a>
<a class="hyperlinks" href="link"> link4 inside specific text 2</a>
<h2>Specific text 3</h2>
<a class="hyperlinks" href="link"> link1 inside specific text 3</a>
<a class="hyperlinks" href="link"> link2 inside specific text 3</a>
</div>
I have to distinctly find links under each "Specific text". The problem is that if I write the following code in python:
links = root.xpath("//div[@id='someid']//a")
for link in links:
print link.attrib['href']
It prints ALL the links irrespective of "Specific Text x", Whereas I want something like:
print "link under Specific text:"+specific+" link:"+link.attrib['href']
Please suggest