为了账号安全,请及时绑定邮箱和手机立即绑定

Scrapy+Xpath+Python:无法抓取数据点

Scrapy+Xpath+Python:无法抓取数据点

慕妹3242003 2021-06-18 10:00:59
我想在这里抓取网址:我试过这些:response.xpath('//header[@class="geodir-entry-header"]/a/@href').extract()response.xpath('//div[class="geodir-content "]/header/a/@href').extract()response.xpath('//div[@class="geodir-content "]/header[@class="geodir-entry-header"]/a/@href').extract()都返回了一个空列表。
查看完整描述

2 回答

?
慕桂英4014372

TA贡献1871条经验 获得超13个赞

response.xpath('//h3[@class="geodir-entry-title"]/a/@href').extract() 或者 response.xpath('//header[@class="geodir-entry-header"]/h3/a/@href').extract()

为你工作?

看起来您刚刚错过了h3包含a您需要的标签的标签。


查看完整回答
反对 回复 2021-06-22
?
紫衣仙女

TA贡献1839条经验 获得超15个赞

您所需要的只是添加您不小心错过的 h3 标签。

response.xpath('//header[@class="geodir-entry-header"]/h3/a/@href').extract()

&如果您只想获取第一个网址,请添加

response.xpath('//header[@class="geodir-entry-header"]/h3/a/@href').extract_first()

或者

response.xpath('//header[@class="geodir-entry-header"]/h3/a/@href').extract()[0]


查看完整回答
反对 回复 2021-06-22
  • 2 回答
  • 0 关注
  • 137 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号