Description: And the previous download Baidu posted pictures almost, modified the regular, added page control;
In addition to the output format control, if you want to join the manual set storage path function, you can refer to the previous Baidu paste stick crawler
#!/usr/bin/env python#!-*-coding:utf-8-*-#图片地址样例: src= "http://ww2.sinaimg.cn/large/005Yan1vjw1erf95qkbfog307e08uu0y.gif" style= "width:460px"ImportUrllib,urllib2ImportRe#返回网页源代码 def gethtml(URL, page):Tempurl = URL + str (page)PrintTempurl html = urllib2.urlopen (tempurl) Srccode = Html.read ()returnSrccode def getimg(URL, start_page, end_page): #对网页中图片建立正则Pattern = Re.compile (R ' src= "(. *?\.gif)". *?style= "width:460px" ') forXinchXrange (Start_page, end_page+1): Srccode = gethtml (url,x)#图片完整路径存储为listIMGSRC = Pattern.findall (srccode) num =0 forIinchImgSrc:urllib.urlretrieve (I,' P%s0%s.gif '% (x, num)) num + =1 Print "Regular Download" PrintIPrint ' All Tasks done! '#-----------The entrance to the program-----------Print u "" "Program starts running #=========================================================# program: Mob Crawler # version: v0.1# before cloud # language: Python 2.7# Action: Enter the range of page numbers for the burst gif you want to download, and automatically download all GIF images #========================================================= "" "#测试urlMyurl =' http://baozoumanhua.com/gif/hot/page/'start_page = Int (Raw_input (u "input start page \ n")) end_page = Int (Raw_input (u "Enter end page \ n")) getimg (Myurl, Start_page, End_page)
[Python] [crawler] Burst gif download