Scrapy Crawl 360 site Images

Source: Internet
Author: User

Project Name: Crawl 360 site Pictures

Target url:http://image.so.com

Project Description: Use Scrapy's imagepipeline to crawl pictures of 360 websites

To grab a picture using scrapy, the first step is to define the item first

1 # -*-coding:utf-8-*- 2 Import scrapy 3 4 class Imageitem (scrapy. Item):5     image_urls = scrapy. Field ()

The second step is to open imagepipeline in settings.py and define the file's storage path.

1 item_pipelines = {2     'scrapy.pipelines.images.ImagesPipeline ': 1,3}45'alfred_images' 

The third step is to write the spider.

1 #-*-coding:utf-8-*-2 Importscrapy3 ImportJSON
From.. Items Import Imageitem4 5 classImagesspider (scrapy. Spider):6Name ='Images'7Start_urls ='http://image.so.com/zj?ch=home&sn=90&listtype=new&temp=1'8 9 defParse (self, response):Tenpics = Json.loads (response.body)#because the JSON data is returned, all of this is one more parsing step . One forIinchpics['List']: Aitem =Imageitem () -item['Image_urls'] = [i["Qhimg_url"]]#Note here that the URL of the picture must be placed in a list, otherwise an exception will occur - yieldItem

A few points to note:

1. It is best to define Image_urls = Field () in item.py

2. Remember to open imagepipeline in settings and define the image storage path

3. The URL of the picture must be placed in the list, must be placed in the list, must be placed in the list.

Scrapy Crawl 360 site Images

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.