学习Scrapy过程中发现用Scrapy下载图片时,总是以他们的URL的SHA1 hash值为文件名,如:

图片URL:http://www.example.com/image.jpg

它的SHA1 hash值为:3afec3b4765f8f0a07b78f98c07b83f013567a0a

则下载的图片为:3afec3b4765f8f0a07b78f98c07b83f013567a0a.jpg

目的是下载的图片为:image.jpg或者xxx.jpg

可以通过编写Pipeline来实现。

以下以下载汽车标志为例子(http://www.pcauto.com.cn/zt/chebiao/)

软件版本:Python2.7  Scrapy(1.0.5),Python3目前对Scrapy支持不好,缺少一些模块

一、创建爬虫工程:

进入某目录下:

scrapy startproject Logo
1
2
3
4
5
6
7
8
9
10
11
目录结构<br>Logo.
│ scrapy.cfg
└─Logo
    │ items.py
    │ pipelines.py
    │ settings.py
    │ __init__.py
    
    └─spiders
           __init__.py

二、

1、在items.py中定义需要爬去信息的变量名称

# -*- coding: utf-8 -*-

# Define here the models for your scraped items
#
# See documentation in:
# http://doc.scrapy.org/en/latest/topics/items.html from scrapy.item import Item, Field class LogoItem(Item):
# define the fields for your item here like:
# name = scrapy.Field()
country=Field()
carname=Field()
imageurl=Field()

2、在Logo/Logo/spiders目录下创建logo_spider.py(名字随意),并写如下代码

#!/usr/bin/env python
# -*- coding:utf-8 -*- from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.selector import Selector
from Logo.items import LogoItem
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.spider import Spider class LogoSpider(CrawlSpider) : #CrawlSpider用来遍布抓取,通过rules来查找所有符合的URL来爬去信息 name = "logo" #名字唯一,启动爬虫是用到 scrapy crawl logo -o items.json
allowed_domains = ["pcauto.com.cn"]
start_urls = ["http://www.pcauto.com.cn/zt/chebiao/faguo/"]
rules = (
Rule(SgmlLinkExtractor(allow = (r'http://www.pcauto.com.cn/zt/chebiao/.*?/$')), follow = True, callback = 'parse_page'),
#将读取的网页进行分析
# Rule(SgmlLinkExtractor(allow = ('http://www\.pcauto.com\.cn/zt/chebiao/.*?/')), callback = 'parse_page')
) def parse_page(self, response) :
sel = Selector(response)
item = LogoItem()
item['country'] = ''.join(sel.xpath('//div[@class="th"]/span[@class="mark"]/a/text()').extract())
item['carname'] = sel.xpath('//div[@class="dTxt"]/i[@class="iTit"]/a/text()').extract()
item['imageurl'] = sel.xpath('//div[@class="dPic"]/i[@class="iPic"]/a/img/@src').extract()
return item # class LogoSpider(Spider) : #抓取单一页面,没有rules # name = "logo"
# allowed_domains = ["pcauto.com.cn"]
# start_urls = ["http://www.pcauto.com.cn/zt/chebiao/faguo/"] # def parse(self, response) :
# sel = Selector(response)
# item = LogoItem()
# item['country'] = ''.join(sel.xpath('//div[@class="th"]/span[@class="mark"]/a/text()').extract())
      #此处 ''.join()是为了在后面为图片自定义名称时使用,若不加''.join(),后面调用item['country']会得到Unicode码
# item['carname'] = sel.xpath('//div[@class="dTxt"]/i[@class="iTit"]/a/text()').extract()
# item['imageurl'] = sel.xpath('//div[@class="dPic"]/i[@class="iPic"]/a/img/@src').extract()
# return item

当抓取的数据中含有中文时,屏幕上打印的数据和保存的数据都显示为Unicode编码,如:

{"carname": ["\u6807\u81f4", "\u96ea\u94c1\u9f99", "\u5e03\u52a0\u8fea", "\u96f7\u8bfa"], "country": "\u6cd5\u56fd\u6c7d\u8f66\u6807\u5fd7", "imageurl": ["http://img0.pcauto.com.cn/pcauto/zt/chebiao/faguo/1108/1446890_peugeot.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/faguo/1108/1446234_citroen.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/faguo/1108/1446234_bugatti.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/faguo/1108/1446890_renault.jpg"]},
应该对应为
{"carname": ["标致", "雪铁龙", "布加迪", "雷诺"], "country": "法国汽车标志", "imageurl": ["http://img0.pcauto.com.cn/pcauto/zt/chebiao/faguo/1108/1446890_peugeot.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/faguo/1108/1446234_citroen.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/faguo/1108/1446234_bugatti.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/faguo/1108/1446890_renault.jpg"]}

要想保存为中文字符,需在pipelines.py中编写如下:

import json
import codecs class JsonWithEncodingPipeline(object): def __init__(self):
self.file = codecs.open('logo.json', 'w', encoding='utf-8')
#当运行scrapy crawl logo -o items.json后,数据默认保存为items.json,里面中文全为Unicode,重新打开或创建一个文件'logo.json',名称随意
def process_item(self, item, spider):
line = json.dumps(dict(item), ensure_ascii=False) + "\n"
self.file.write(line)
return item def spider_closed(self, spider):
self.file.close()

已过以上步骤后CMD输入scrapy crawl logo -o items.json,会得到文件logo.json

{"carname": ["起亚", "双龙", "现代"], "country": "韩国汽车标志", "imageurl": ["http://img0.pcauto.com.cn/pcauto/zt/chebiao/hanguo/1108/1446890_kia.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/hanguo/1108/1446890_shuanglong.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/hanguo/1108/1446234_hyundai.jpg"]}
{"carname": ["丰田", "本田", "马自达", "日产", "斯巴鲁", "雷克萨斯", "讴歌", "铃木", "英菲尼迪", "三菱", "光冈"], "country": "日本汽车标志", "imageurl": ["http://img0.pcauto.com.cn/pcauto/zt/chebiao/riben/1108/1446890_toyota.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/riben/1108/1446234_honda.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/riben/1108/1446890_mazda.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/riben/1108/1446890_nissan.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/riben/1108/1446890_subaru.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/riben/1108/1446890_lexus.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/riben/1108/1446234_acura.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/riben/1108/1446890_suzuki.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/riben/1108/1446234_infiniti.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/riben/1108/1446890_mitsubishi.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/riben/1108/1446234_guanggang.jpg"]}
{"carname": ["标致", "雪铁龙", "布加迪", "雷诺"], "country": "法国汽车标志", "imageurl": ["http://img0.pcauto.com.cn/pcauto/zt/chebiao/faguo/1108/1446890_peugeot.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/faguo/1108/1446234_citroen.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/faguo/1108/1446234_bugatti.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/faguo/1108/1446890_renault.jpg"]}
{"carname": ["凯迪拉克", "雪佛兰", "福特", "别克", "克莱斯勒", "悍马", "GMC", "林肯", "吉普", "道奇", "Rossion"], "country": "美国汽车标志", "imageurl": ["http://img0.pcauto.com.cn/pcauto/zt/chebiao/meiguo/1108/1446234_cadillac.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/meiguo/1108/1446234_chevrolet.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/meiguo/1108/1446234_ford.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/meiguo/1108/1511925_buick8060.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/meiguo/1108/1446234_chrysler.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/meiguo/1108/1446234_hummer.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/meiguo/1108/1446234_gmc.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/meiguo/1108/1446890_lincoln.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/meiguo/1108/1446234_jeep.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/meiguo/1108/1447012_dodge.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/meiguo/1108/1451297_rossion.jpg"]}
{"carname": ["斯柯达", "柯尼塞格", "西亚特", "世爵", "萨博", "沃尔沃"], "country": "其他汽车标志", "imageurl": ["http://img0.pcauto.com.cn/pcauto/zt/chebiao/qita/1108/1486098_skoda8060.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/qita/1108/1446890_koenigsegg.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/qita/1108/1486068_seat8060.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/qita/1108/1446890_spykers.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/qita/1108/1446890_saab.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/qita/1108/1446890_volvo.jpg"]}
{"carname": ["劳斯莱斯", "保时捷", "奔驰", "宝马", "奥迪", "大众", "劳伦士", "欧宝", "迈巴赫", "Smart"], "country": "德国汽车标志", "imageurl": ["http://img0.pcauto.com.cn/pcauto/zt/chebiao/deguo/1108/1446890_rolls-royce.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/deguo/1108/1446890_porsche.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/deguo/1108/1446234_benz.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/deguo/1108/1446234_bmw.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/deguo/1108/1446234_audi.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/deguo/1108/1446890_volkswagen.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/deguo/1108/1528840_8060.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/deguo/1108/1446890_opel.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/deguo/1108/1446890_maybach.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/deguo/1108/1446890_smart.jpg"]}
{"carname": ["宾利", "迷你", "路特斯", "阿斯顿马丁", "捷豹", "路虎"], "country": "英国汽车标志", "imageurl": ["http://img0.pcauto.com.cn/pcauto/zt/chebiao/yingguo/1108/1446234_bentley.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/yingguo/1108/1446890_mini.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/yingguo/1108/1518508_Lotus8060.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/yingguo/1108/1446234_aston-martin.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/yingguo/1108/1446234_jaguar.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/yingguo/1108/1446890_landrover.jpg"]}
{"carname": ["法拉利", "帕加尼", "玛莎拉蒂", "兰博基尼", "阿尔法罗密欧", "菲亚特"], "country": "意大利汽车标志", "imageurl": ["http://img0.pcauto.com.cn/pcauto/zt/chebiao/yidali/1108/1446234_ferrari.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/yidali/1108/1451297_pagani.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/yidali/1108/1446890_maserati.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/yidali/1108/1447114_5.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/yidali/1108/1328198_romio.png", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/yidali/1108/1446234_fiat.jpg"]}
{"carname": ["广汽", "奇瑞", "一汽", "比亚迪", "长城", "MG", "庆铃", "力帆", "陆风", "吉奥", "奔腾", "众泰", "中华", "荣威", "厦门金龙", "英伦汽车", "风神", "海马郑州", "长安(商用)", "启辰", "莲花", "汇众", "华普", "昌河", "福迪", "五菱", "长安", "中兴", "吉林", "威旺", "纳智捷", "宝骏", "依维柯", "解放", "川汽野马", "红旗", "黑豹", "哈飞", "江铃", "福田", "双环", "华泰", "长丰", "东南", "海马", "吉利", "帝豪", "江淮", "东风", "金杯", "瑞麒", "九龙", "黄海", "全球鹰", "开瑞", "威麟", "北京汽车", "理念", "北汽", "南汽", "中顺", "江南", "大迪", "永源", "自由风", "中欧"], "country": "国产汽车标志", "imageurl": ["http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_guangqi.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_chery.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446890_yiqi.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_byd.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_greatwall.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446890_mg.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1592575_121.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446890_lifan.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446890_lufeng.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1520427_ja8060.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_benten.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1573305_zhongtai8060.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446890_zhonghua.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446890_roewe.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_jinlonglianhe.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446890_yinglun.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1447032_dongfengfengshen.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_haimashangyong.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_changanshangyong.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1508050_qichen5050.png", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446890_lotus-motor.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1451297_huizong.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_huapu.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_changhe.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_fudi.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446890_wuling.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_chaanjiaoche.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446890_zhongxing.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446890_yiqi.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1531565_ww8060.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1486099_nazhijie8060.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_baojun.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_iveco.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1328218_yq.png", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1328218_cq.png", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_hongqi.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1451297_heibao.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_hafei.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_jiangling.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_futian.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446890_shuanghuan.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_huatai.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_changfeng.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446890_soueast-motor.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_haima.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_geely.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1447012_dihao.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_jac.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1447012_dongfeng.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_huachenjinbei.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446890_riich.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1451708_jiulong.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_huanghai.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446890_quanqiuying.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446890_karry.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446890_ruilink.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_beijingqiche.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1455155_ln.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_baw.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446890_xinyatu.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1328198_zs.png", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446234_jiangnan.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1447012_dadi.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1446890_ufo.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1451297_ziyoufeng.jpg", "http://img0.pcauto.com.cn/pcauto/zt/chebiao/guochan/1108/1451297_zhongou.jpg"]}

3、上面只是对抓取的数据进行了保存,还未下载图片,打开pipelines.py

# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html
from scrapy.pipelines.images import ImagesPipeline
from scrapy.exceptions import DropItem
from scrapy import Request
import json
import codecs class JsonWithEncodingPipeline(object): def __init__(self):
self.file = codecs.open('logo.json', 'w', encoding='utf-8') def process_item(self, item, spider):
line = json.dumps(dict(item), ensure_ascii=False) + "\n"
self.file.write(line)
return item def spider_closed(self, spider):
self.file.close() class DownloadImagesPipeline(ImagesPipeline):
def get_media_requests(self,item,info): #下载图片
for image_url in item['imageurl']:
yield Request(image_url,meta={'item':item,'index':item['imageurl'].index(image_url)}) #添加meta是为了下面重命名文件名使用 def file_path(self,request,response=None,info=None):
item=request.meta['item'] #通过上面的meta传递过来item
index=request.meta['index'] #通过上面的index传递过来列表中当前下载图片的下标 #图片文件名,item['carname'][index]得到汽车名称,request.url.split('/')[-1].split('.')[-1]得到图片后缀jpg,png
image_guid = item['carname'][index]+'.'+request.url.split('/')[-1].split('.')[-1]
#图片下载目录 此处item['country']即需要前面item['country']=''.join()......,否则目录名会变成\u97e9\u56fd\u6c7d\u8f66\u6807\u5fd7\xxx.jpg
filename = u'full/{0}/{1}'.format(item['country'], image_guid)
return filename

4、setting.py中

BOT_NAME = 'Logo'

SPIDER_MODULES = ['Logo.spiders']
NEWSPIDER_MODULE = 'Logo.spiders' ITEM_PIPELINES={
# 'sucai.pipelines.SucaiPipeline':1
'Logo.pipelines.JsonWithEncodingPipeline':2,
'Logo.pipelines.DownloadImagesPipeline':1
}
IMAGES_STORE='F:\Logo\picture'

然后运行scrapy crawl logo -o items.json,

Logo.
│ items.json
│ logo.json
│ scrapy.cfg

├─Logo
│ │ items.py
│ │ items.pyc
│ │ pipelines.py
│ │ pipelines.pyc
│ │ settings.py
│ │ settings.pyc
│ │ __init__.py
│ │ __init__.pyc
│ │
│ └─spiders
│ logo_spider.py
│ logo_spider.pyc
│ __init__.py
│ __init__.pyc

└─picture
└─full
├─其他汽车标志
│ 世爵.jpg
│ 斯柯达.jpg
│ 柯尼塞格.jpg
│ 沃尔沃.jpg
│ 萨博.jpg
│ 西亚特.jpg

├─国产汽车标志
│ MG.jpg
│ 一汽.jpg
│ 东南.jpg
│ 东风.jpg
│ 中兴.jpg
│ 中华.jpg
│ 中欧.jpg
│ 中顺.png
│ 九龙.jpg
│ 五菱.jpg
│ 众泰.jpg
│ 依维柯.jpg
│ 全球鹰.jpg
│ 力帆.jpg
│ 北京汽车.jpg
│ 北汽.jpg
│ 华普.jpg
│ 华泰.jpg
│ 南汽.jpg
│ 厦门金龙.jpg
│ 双环.jpg
│ 吉利.jpg
│ 吉奥.jpg
│ 启辰.png
│ 哈飞.jpg
│ 大迪.jpg
│ 奇瑞.jpg
│ 奔腾.jpg
│ 威旺.jpg
│ 威麟.jpg
│ 宝骏.jpg
│ 川汽野马.png
│ 帝豪.jpg
│ 广汽.jpg
│ 庆铃.jpg
│ 开瑞.jpg
│ 昌河.jpg
│ 比亚迪.jpg
│ 永源.jpg
│ 汇众.jpg
│ 江南.jpg
│ 江淮.jpg
│ 江铃.jpg
│ 海马.jpg
│ 海马郑州.jpg
│ 理念.jpg
│ 瑞麒.jpg
│ 福田.jpg
│ 福迪.jpg
│ 红旗.jpg
│ 纳智捷.jpg
│ 自由风.jpg
│ 英伦汽车.jpg
│ 荣威.jpg
│ 莲花.jpg
│ 解放.png
│ 金杯.jpg
│ 长丰.jpg
│ 长城.jpg
│ 长安.jpg
│ 长安(商用).jpg
│ 陆风.jpg
│ 风神.jpg
│ 黄海.jpg
│ 黑豹.jpg

├─德国汽车标志
│ Smart.jpg
│ 保时捷.jpg
│ 劳伦士.jpg
│ 劳斯莱斯.jpg
│ 大众.jpg
│ 奔驰.jpg
│ 奥迪.jpg
│ 宝马.jpg
│ 欧宝.jpg
│ 迈巴赫.jpg

├─意大利汽车标志
│ 兰博基尼.jpg
│ 帕加尼.jpg
│ 法拉利.jpg
│ 玛莎拉蒂.jpg
│ 菲亚特.jpg
│ 阿尔法罗密欧.png

├─日本汽车标志
│ 三菱.jpg
│ 丰田.jpg
│ 光冈.jpg
│ 斯巴鲁.jpg
│ 日产.jpg
│ 本田.jpg
│ 英菲尼迪.jpg
│ 讴歌.jpg
│ 铃木.jpg
│ 雷克萨斯.jpg
│ 马自达.jpg

├─法国汽车标志
│ 布加迪.jpg
│ 标致.jpg
│ 雪铁龙.jpg
│ 雷诺.jpg

├─美国汽车标志
│ GMC.jpg
│ Rossion.jpg
│ 克莱斯勒.jpg
│ 凯迪拉克.jpg
│ 别克.jpg
│ 吉普.jpg
│ 悍马.jpg
│ 林肯.jpg
│ 福特.jpg
│ 道奇.jpg
│ 雪佛兰.jpg

├─英国汽车标志
│ 宾利.jpg
│ 捷豹.jpg
│ 路特斯.jpg
│ 路虎.jpg
│ 迷你.jpg
│ 阿斯顿马丁.jpg

└─韩国汽车标志
双龙.jpg
现代.jpg
起亚.jpg
 
 

Day3-scrapy爬虫下载图片自定义名称的更多相关文章

  1. 用Scrapy爬虫下载图片(豆瓣电影图片)

    用Scrapy爬虫的安装和入门教程,这里有,这篇链接的博客也是我这篇博客的基础. 其实我完全可以直接在上面那篇博客中的代码中直接加入我要下载图片的部分代码的,但是由于上述博客中的代码已运行,已爬到快九 ...

  2. Scrapy——6 APP抓包—scrapy框架下载图片

    Scrapy——6 怎样进行APP抓包 scrapy框架抓取APP豆果美食数据 怎样用scrapy框架下载图片 怎样用scrapy框架去下载斗鱼APP的图片? Scrapy创建下载图片常见那些问题 怎 ...

  3. scrapy批量下载图片

    # -*- coding: utf-8 -*- import scrapy from rihan.items import RihanItem class RihanspiderSpider(scra ...

  4. Python学习---网页爬虫[下载图片]

    爬虫学习--下载图片 1.主要用到了urllib和re库 2.利用urllib.urlopen()函数获得页面源代码 3.利用正则匹配图片类型,当然正则越准确,下载的越多 4.利用urllib.url ...

  5. ZH奶酪:PHP (爬虫)下载图片

    原文地址:http://www.phpfensi.com/php/20140107/1128.html 通过图片地地址把图片保存到本址,这里我们直接通过readfile读取然后通过fopen保存即可, ...

  6. python 爬虫--下载图片,下载音乐

    #下载图片 imgUrl='http://www.pptbz.com/pptpic/UploadFiles_6909/201211/2012111719294197.jpg' r=requests.g ...

  7. Python网络爬虫 - 下载图片

    下载博客园的logo from urllib.request import urlretrieve from urllib.request import urlopen from bs4 import ...

  8. scrapy基础知识之scrapy自动下载图片pipelines

    需要在settings.py配置: ITEM_PIPELINES = { 'scrapy.pipelines.images.ImagesPipeline': 1, }import os IMAGES_ ...

  9. 【Python】python3实现网页爬虫下载图片

    import re import urllib.request # ------ 获取网页源代码的方法 --- def getHtml(url): page = urllib.request.urlo ...

随机推荐

  1. org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout() mybatis和spring-mybatis版本不匹配问题

    java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()  ...

  2. eclipse maven jar工程导出项目依赖的jar包

    今天遇到个事,给业务开发/测试搞个了转换工具,是使用swing写的,依赖了很多的三方包,为了方便打算以bat方式提供,但是要导出依赖的三方jar,网上搜了下,如下(已测试): 一.导出到默认目录 ta ...

  3. 【题解】Luogu P1503 鬼子进村

    平衡树好题 原题传送门 这道题要用Splay,我博客里有对Splay的详细介绍 这道题思维有点难,要把被摧毁的节点插入平衡树,而不是把没有摧毁的节点插入 先把0和n+1插入平衡树,作为边界 操作1:摧 ...

  4. linux服务器启动报错UNEXPECTED INCONSISTENCY解决方法

    内网的linux服务器给开发员用来测试以及共享文件使用,今天早上发现xshell连接不上该服务器,一开始进入系统显示reboot and select proper boot device or in ...

  5. Thinkphp5 分页带参数

    原文链接:http://www.zhaisui.com/article/51.html

  6. NOIP 2016 换教室 (luogu 1850 & uoj 262) - 概率与期望 - 动态规划

    题目描述 对于刚上大学的牛牛来说,他面临的第一个问题是如何根据实际情况申请合适的课程. 在可以选择的课程中,有 2n2n 节课程安排在 nn 个时间段上.在第 ii(1 \leq i \leq n1≤ ...

  7. css3-动画(animation)

    css3-动画(animation): 具有以下属性: 1.animation-name 自定义动画名称 2.animation-duration 动画指定需要多少秒或毫秒完成,默认值是0; 3.an ...

  8. java Swing小知识点

    private JTextArea jta=new JTextArea(1,2); private ScrollPane sp=new ScrollPane(); private JPasswordF ...

  9. 剪格子|2013年蓝桥杯A组题解析第九题-fishers

    剪格子 如图p1.jpg所示,3 x 3 的格子中填写了一些整数. 我们沿着图中的红色线剪开,得到两个部分,每个部分的数字和都是60. 本题的要求就是请你编程判定:对给定的m x n 的格子中的整数, ...

  10. ZOJ 3962 Seven Segment Display(数位DP)题解

    题意:给一个16进制8位数,给定每个数字的贡献,问你贡献和. 思路:数位DP,想了很久用什么表示状态,看题解说用和就行,其他的都算是比较正常的数位DP. 代码: #include<iostrea ...