Python bulk download image of Mowgli and Hummingbird pictures crawler Small application

Source: Internet
Author: User

Some redundancy information. As a result of the previous test is the form of the formula. So they were not removed. Just do not affect the use.
#-*-Coding:utf-8-*-import re,urllib,sys,os,timedef getallurl (): entry=sys.argv[1] #try: Getpage=urllib.urlopen ( Entry). Read () #except: #print "Error" Pattern=re.compile (R ' <a href= "(. +?

".+?> ') Web_site_pattern=re.compile (R ' (http:.+?) ') All_url = Pattern.findall (getpage) for URLs in All_url:if web_site_pattern.match (URLs):p rint url#print urlprint "Done" def Download_pic (): url=sys.argv[1]; #local_path = "c:/tools/source/" Connection=urllib.urlopen (URL) data= Connection.read () print "Waiting to get Data" Time.sleep (3) connection.close () #analyze #p =re.compile (R ' img width= "\d+". +src= "(. +)". + ') Download_pic_pattern=re.compile (R ' ') #p10 =re.compile (R ' (. +) \.jpg ' ) All_url=download_pic_pattern.findall (data) #print all_urli=1directory= "C:/tools/source" Name_pattern=re.compile ( R '/(\w+?\.jpg) ') if not os.path.exists (directory): Os.mkdir (directory) for URLs in All_url:print urls#print "Working" # Print Local_pathi=i+1name=name_pattern.findall (URLs) print name[0]local_path= "c:/tools/source/%s"% name[0] Jpeg_ Connection=urllib.urlopen (URLs) jpeg=jpeg_connection.read () time.sleep (1) print "Waiting" F=file (Local_path, "WB") F.write (JPEG) f.close () jpeg_connection.close () #i =i+1#f=file(Local_path, "WB") #f. Write (data) #f. Close () print ("Done") def download_pic_2 (): url=sys.argv[1];local_path= "C:/tools /a.jpg "Data=urllib.urlretrieve (url,local_path) print (" Done ") def Regulation (): str1=" abc123*gbk1024abc*defb1kc12* ADDD "P1=re.compile (R ' abc ') print P1.findall (str1) p2=re.compile (R ' a.c ') print P2.findall (str1) p3=re.compile (R ' abc\* ') print P3.findall (str1) p4=re.compile (R ' [abc]12 ') print P4.findall (str1) p5=re.compile (R ' \d\* ') print P5.findall ( STR1) P6=re.compile (R ' a[^\d] ') print P6.findall (str1) p7=re.compile (R ' a[^\d]* ') print P7.findall (str1) P8=re.compile ( R ' [a-za-z]+ (\d+) ') print P8.findall (str1) str2= "Dadfae ef Asdfe Aa<ima "p9=re.compile (R '


###### #兴许

Later changed the code, using BeautifulSoup, to be able to download a wider range of images

Code such as the following: HTTP://WWW.30DAYDO.COM/ARTICLE/56


Python bulk download image of Mowgli and Hummingbird pictures crawler Small application

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.