How to extract data-href using xpath in python



This is the xml format I want to extract data from: enter image description here


What I tried is:



import requests
from lxml import html
content=requests.get(url).content
tree=html.fromstring(content)
links=tree.xpath('//h3[@class="r"]/a/@data-href')
out="\n".join([str(x) for x in links]).strip('\r\n')+'\r\n'
print links
print out


But for printing links and out I have nothing as result...


No comments:

Post a Comment