在Scrapy中使用Xpath返回空值
我真的需要这个社区的帮助 我的问题是当我使用代码时 ========================================================================= xpath(//div[contains(@class,'check-prices-widget-not-sponsorted')]/a/div[contains(@class,'check-prices-widget-not-sponsorted-link'))”)。extract() 要提取scrapy shell中的供应商名称,输出为空。我真的不知道为什么会发生这种情况,在我看来,问题可能是网站信息正在动态更新 这个网页抓取的url是:,我需要的是每个供应商的供应商名称和价格。此外,所附图片是“检查”的屏幕截图在Scrapy中使用Xpath返回空值,xpath,scrapy,isnullorempty,Xpath,Scrapy,Isnullorempty,我真的需要这个社区的帮助 我的问题是当我使用代码时 ========================================================================= xpath(//div[contains(@class,'check-prices-widget-not-sponsorted')]/a/div[contains(@class,'check-prices-widget-not-sponsorted-link'))”)。extract() 要提取sc
非常感谢你的帮助 您需要始终检查浏览器中的HTML源代码(通常使用Ctrl+U) 通过这种方式,您会发现您想要的信息被嵌入到使用JSON的Javascript变量中:
var partnerPrices = [{"pool":"9a316391b6550eef969c8559c14a380f","partner":"ncl.com","priority":0,"currency":"USD","data":{"32860":{"2018-02-25":{"Inside":579,"Suite":1199,"Balcony":699,"Oceanview":629},....
var sponsored_partners = [{"code":"CDCNA","name":"cruises.com","value":"cruises.com","logo":"\/images\/partner-logo-cruises-sm.png","logo_sprite":"partner-logo-cruises-com"},...
因此,您需要导入json
,解析response.body
(使用re
或其他方法),然后json.loads()
解析的json字符串以迭代两个数组