python petals Beauty Download
Author: VpoetDate: About in the summerNote: The code is free copy don't tell me
main functions:1. Search for pictures under petal http://huaban.com/2. Number of downloaded images selected3. Show Download Progress4. Create a directory and download it to the desktop
note Less, make a look.
#coding: Utf-8import urllib, URLLIB2, RE, sys, osimport randomreload (SYS) def Schedule (a,b,c): "" "A: Downloaded data block B: large chunk of data Small C: The size of the remote file "" "per = 100.0 * A * b/c if per > 100:per = + print '%.2f%% '% perdef searchanddown Loadimg (searchstr,numperpage,filepath): url = ' http://huaban.com/search/?q=%s&per_page=%s '% (Searchstr,str (Num perpage)) Respon = Urllib2.urlopen (URL) Htm = Respon.read () print url+ "\n\n\n" print "-------- --------Search over,and Begin DownLoad----------------"+" \ n "patt=re.compile ('" File ": \{" Farm ":" Farm1 ",. +?" Bucket ":" hbimg ",. +?" Key ":" (. *?) ",. +?" Type ":" image/(. *?) ",. +?" Width ": ') group = Re.findall (patt,htm) #print" Find Total Imgurl "+len (group) +" \ n "x = 1 for it EM in Group:imgurl=r "http://img.hb.aicdn.com/" +item[0]+ "_fw658" Urllib.urlretrieve (Imgurl,filep ath+ ' \pic%s.%s '% (str (x), item[1]), Schedule) print imgurl+ "------>down oveR "+" \tpic "+ str (x) x = x+1 if __name__ = =" __main__ ": print" Please input the picture you WA NT to download: "SEARCHSTR = Raw_input () print" \ n "print" Please input the pagenumber your want to Download: "Numperpage = Raw_input () print" \ n "print"-----------------------Begin Search---------- -----------------"+" \ n "filenum = random.randint (+) filename = ' picturefile ' +str (filenum) fi Lepath = ' C:\Users\Administrator\Desktop ' + ' \ \ ' +filename if (os.path.exists (filepath) = = False): Os.mkdir (file Path) #print filepath searchanddownloadimg (searchstr,numperpage,filepath) #http://IMG.HB.AICDN.COM/23 A58517FB73F86BCA85937F069724486B3E00A44CAA-GMC99I_SQ75SF print "\ n" print "---------------------all down Ov Er-----------------------"
Run:search beatuiful, download 20 photos
Petal Search Results:
Run, show download progress:
Image Crawl Results:
Python petals Beauty Download