I've selected the element in a page that has the links I want to the pages. They are sort of like <a href="blah">1</a>
. I want to use regex with xpath so that I can get all the links like that one, whose text is \d+
.
I see there is an answer for it here: How to use regular expression in lxml xpath? but I can't make sense out of it.
More specifically, "Note that you need to give the namespace mapping, so that it knows what the "re" prefix in the xpath expression stands for."
Here's the code from the page cleaned up: <div class="pagination"> <b>1</b> <a href="?page=post&s=list&tags=tag2+tag1&pid=25">2</a><a href="?page=post&s=list&tags=tag2+tag1&pid=50">3</a><a href="?page=post&s=list&tags=tag2+tag1&pid=75">4</a><a href="?page=post&s=list&tags=tag2+tag1&pid=100">5</a><a href="?page=post&s=list&tags=tag2+tag1&pid=125">6</a><a href="?page=post&s=list&tags=tag2+tag1&pid=150">7</a><a href="?page=post&s=list&tags=tag2+tag1&pid=175">8</a><a href="?page=post&s=list&tags=tag2+tag1&pid=200">9</a><a href="?page=post&s=list&tags=tag2+tag1&pid=225">10</a><a href="?page=post&s=list&tags=tag2+tag1&pid=250">11</a><a href="?page=post&s=list&tags=tag2+tag1&pid=25" alt="next">›</a><a href="?page=post&s=list&tags=tag2+tag1&pid=325" alt="last page">»</a><br><br><br><br><iframe hspace="0" vspace="0" border="0" marginheight="0" marginwidth="0" allowtransparency="true" src="http://notrelevant.com" frameborder="0" height="98" scrolling="no" width="736"></iframe></div>
My code so far:
answer = browser.open(address)
tree = lxml.html.parse(answer)
numbers = tree.xpath("//div[contains(@class, 'pagination')]")[0]