簡體   English   中英

由於命名空間,使用 Scrapy Python 無法從帶有 xpath 的響應 html 中提取數據

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

我正在使用帶有 xpath 的 scrapy 從網頁中提取數據。 我的 html 響應如下所示,

在此處輸入圖片說明

我想提取突出顯示的“a”標簽中存在的 href 鏈接。

通常我使用response.xpath('//a[@id="jr-alt-sw"]/@href')來獲取數據,但在這里我認為由於命名空間問題,結果為空。 如果存在命名空間,我如何獲取數據。

任何幫助表示贊賞!

命名空間是真的嗎? 使用 css 的另一個原因:

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

此處選擇的a標簽沒有可用的href屬性,請查看下a包含href屬性的a標簽。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM