关于保存图片的问题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 请老师指点为什么新闻详情页里有多张图片的时候,只能下载下来一张啊? class DongqiudiImagePipeline(ImagesPipeline): def get_media_requests( self , item, info): for image_url in item[ 'image_urls' ]: yield scrapy.Request(url = image_url, meta = { "item" : item}) def item_completed( self , results, item, info): image_paths = [] for ok, x in results: if ok: image_paths.append(x[ 'path' ]) if not image_paths: raise DropItem( 'Item contains no images' ) def file_path( self , request, response = None , info = None ): img_name = request.meta[ 'item' ][ 'title' ] + '.jpg' return img_name crawl_dongqiudi中获取image_urls的xpath news_info[ 'image_urls' ] = response.xpath( "//div[@class='con']/div/p/img/@data-src" ).extract() |
17
收起
正在回答 回答被采纳积分+1
1回答
4.入门主流框架Scrapy与爬虫项目实战
- 参与学习 人
- 提交作业 107 份
- 解答问题 1672 个
Python最广为人知的应用就是爬虫了,有趣且酷的爬虫技能并没有那么遥远,本阶段带你学会利用主流Scrapy框架完成爬取招聘网站和二手车网站的项目实战。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧