【发布时间】:2018-12-10 20:36:15
【问题描述】:
我用 python scrapy 编写了一个脚本来从网站下载一些图像。当我运行我的脚本时,我可以在控制台中看到图像的链接(它们都是.jpg 格式)。但是,当我打开下载完成后应该保存图像的文件夹时,我什么也没有。我哪里出错了?
这是我的蜘蛛(我从 sublime 文本编辑器运行):
import scrapy
from scrapy.crawler import CrawlerProcess
class YifyTorrentSpider(scrapy.Spider):
name = "yifytorrent"
start_urls= ['https://www.yify-torrent.org/search/1080p/']
def parse(self, response):
for q in response.css("article.img-item .poster-thumb"):
image = response.urljoin(q.css("::attr(src)").extract_first())
yield {'':image}
c = CrawlerProcess({
'USER_AGENT': 'Mozilla/5.0',
})
c.crawl(YifyTorrentSpider)
c.start()
这是我在settings.py 中为要保存的图像定义的:
ITEM_PIPELINES = {
'scrapy.pipelines.images.ImagesPipeline': 1,
}
IMAGES_STORE = "/Desktop/torrentspider/torrentspider/spiders/Images"
为了让事情更清楚:
- 我希望保存图像的文件夹名为
Images,我已将其放置在项目torrentspider下的spider文件夹中。 -
Images文件夹的实际地址是C:\Users\WCS\Desktop\torrentspider\torrentspider\spiders。
这不是在items.py 文件的帮助下成功运行脚本。因此,任何使用items.py 文件进行下载的解决方案都不是我想要的。
【问题讨论】:
标签: python python-3.x web-scraping scrapy scrapy-spider