简体   繁体   中英

Using Scrapy Python not able to extract data from response html with xpath due to namespace

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

在此处输入图片说明

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!!

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

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

此处选择的a标签没有可用的href属性,请查看下a包含href属性的a标签。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM