0
votes

I am using scrapy with xpath to extract data from a webpage. My html response looks like this,

enter image description here

I want to extract the href link present in the highlighted "a" tag.

Usually I use response.xpath('//a[@id="jr-alt-sw"]/@href') to get the data, but here I think due to the namespace problem the result is empty. How can I get the data if namespace is present.

Any help is appreciated!!

2
What namespace issue are you referring to? We need a minimal reproducible example. Also, please do not share information as images unless absolutely necessary. See: meta.stackoverflow.com/questions/303812/…, idownvotedbecau.se/imageofcode, idownvotedbecau.se/imageofanexception.AMC
there is no href attribute for the highlighted a tag in here.Arun Augustine

2 Answers

0
votes

Is that true about namespace? Another reason to use css instead:

response.css('a#jr-alt-sw::attr(href)')
0
votes

There is no href attribute available for the selected a tag here, Check out for the next a tag that contains the href attribute.

response.xpath('//a[@id="jr-pdf-sw"]/@href')