我正在尝试从产品图库下载所有图像。我已经尝试了上述脚本,但不知何故,我无法下载图像。我可以设法下载包含ID的主图像。图库中的其他图像不包含任何ID,我无法下载它们。
import scrapy
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule
class BasicSpider(CrawlSpider):
name = 'basic'
allowed_domains = ['www.leebmann24.de']
start_urls = ['https://www.leebmann24.de/bmw.html']
rules = (
Rule(LinkExtractor(restrict_xpaths="//div[@class='category-products']/ul/li/h2/a"), callback='parse_item'),
Rule(LinkExtractor(restrict_xpaths="//li[@class='next']/a"), callback='parse_item', follow=True),
)
def parse_item(self, response):
yield {
'URL': response.url,
'Price': response.xpath("normalize-space(//span[@class='price']/text())").get(),
'image_urls': response.xpath("//div[@class='item']/a/img/@src").getall()
}
2条答案
按热度按时间mzillmmw1#
@Raisul Islam,
'//*[@id="image-main"]/@src'
正在生成图像URL,我没有遇到任何问题。请查看输出,无论这是否是您的期望。输出:
f2uvfpb92#
此表达式将获取除main之外的所有产品图像(您说您已经拥有它):