Python crawler for crawling web images

Source: Internet
Author: User


In the bar when you see the bar paste inside the beautiful picture, or have beautiful sister paper pictures, is not want to save it?

But some pages of pictures more, one by one to save more trouble.

Recently learning Python, so using Python to crawl the content of the Web is more convenient:

So I tried it for a bit.


------Code-------

#coding =utf-8import re   import urllib   //Import Module    def  gethtml (URL):    //Custom function to get Web page content    page=urllib.urlopen (URL)     html=page.read ()    return htmldef getimg (HTML):    //Custom Function, Get the content you need    reg=r ' src= ' (. +?\.jpg) " pic_ext '  //regular expressions, grab image links, see html.jpg    Imgre=re.compile (REG)            //compiles the regular expression into a regular expression object, To improve the crawl efficiency     imglist=re.findall (imgre,html)   //get all the matching regular expression objects in the HTML     x=1   for imgurl in imglist:           //loops through the entire list of links       urllib.urlretrieve (Imgurl, ' f:\\myimg\\ Myimage\\ %s.jpg '  % x)  //save picture to target folder       x=x+1       html=gethtml ("  //to get the page link  print getimg (HTML)-----------------------------------diagram: If you have any questions, please download the graphic image to view my Cheetah browser.


This article is from the "Kuing Home pages" blog, so be sure to keep this source http://kuing.blog.51cto.com/9635522/1709672

Python crawler for crawling web 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.