Xpath Parsing The Whole Page When I Specify Not To
I'm parsing websites using python and XPath. What I'm trying to do is to extract the href from the So here's how is the XML (page):
Solution 1:
An XPath starting with a /
character means that it will be begin at the document root node. To create a relative XPath from the context node, you need to put a .
before the /
.
So your code should be:
posts = page.xpath("//div[@id='posts']/div[@align='center']")
for post in posts:
print post.xpath(".//table/tr[1]/td[2]/a/@href")
Post a Comment for "Xpath Parsing The Whole Page When I Specify Not To"