【发布时间】:2020-07-12 15:15:39
【问题描述】:
我需要从“https://www.gizbot.com/mobile-brands-in-india/”中提取图像 src 以及品牌名称。 我试过用scrapy- 蜘蛛.py
def parse(self, response):
page = response.url.split("/")[-2]
filename = 'mobiles-%s.html' % page
mob = response.xpath('.//div[has-class("all-brands-block-desc-brand")]/text()').getall()
for mobile in mob:
m = str(mobile).split()[0]
with open(filename, 'a') as f:
f.write("%s %s\n" % (mobile, response.xpath('.//a[contains(@href, m)]').xpath("@href").extract()))
self.log('Saved file %s' % filename)
但它没有提取正确的数据。我不知道我哪里出错了。感谢任何帮助。
【问题讨论】:
-
用于提取图像 src。对于我在 response.css('div.all-brands-block'): print("gizbot.com" + i.css('img::attr("data-pagespeed-lazy-src")').get ())
标签: python-3.x web-scraping scrapy