python之花瓣美女下载,python花瓣美女,作者:vpoet日期:大
python之花瓣美女下载,python花瓣美女,作者:vpoet日期:大
作者:vpoet日期:大约在夏季注:代码随意copy不用告诉我主要功能: 1.搜索花瓣http://huaban.com/下的图片 2.选定下载图片数目 3.显示下载进度 4.创建目录并下载到桌面注释少,凑合看。```python #coding: utf-8
import urllib, urllib2, re, sys, os
import random
reload(sys)
def Schedule(a,b,c): """a:已经下载的数据块 b:数据块的大小 c:远程文件的大小""" per = 100.0 * a * b / c if per > 100: per = 100 print '%.2f%%' % perdef SearchAndDownLoadImg(SearchStr,NumPerPage,filepath): url = 'http://huaban.com/search/?q=%s&per_page=%s' % (SearchStr,str(NumPerPage)) Respon = urllib2.urlopen(url) Htm = Respon.read() print url+"\n\n\n" print "----------------Search Over,And Begin DownLoad----------------"+"\n\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 item in group: imgurl=r"http://img.hb.aicdn.com/"+item[0]+"_fw658" urllib.urlretrieve(imgurl,filepath+'\pic%s.%s' % (str(x),item[1]),Schedule) print imgurl+"------>down over" +"\tpic"+ str(x) x = x+1if __name__ == "__main__": print "Please input the picture you want to download:" SearchStr = raw_input() print "\n\n" print "Please input the PageNumber you want to download:" NumPerPage = raw_input() print "\n\n" print "-----------------------Begin Search---------------------------"+"\n" filenum = random.randint(20, 50) filename = 'PictureFile'+str(filenum) filepath = 'C:\Users\Administrator\Desktop'+'\\'+filename if(os.path.exists(filepath) == False): os.mkdir(filepath) #print filepath SearchAndDownLoadImg(SearchStr,NumPerPage,filepath) #http://img.hb.aicdn.com/23a58517fb73f86bca85937f069724486b3e00a44caa-GMc99I_sq75sf print"\n\n" print "---------------------All Down Over-----------------------"
```
相关内容
- Python 发送带附件的email,pythonemail,None
- python图片小爬虫,,import re i
- python给图片右上角加上红色的数字,,from PIL imp
- python改变图片尺寸,,from PIL imp
- python programming exercise facemove,pythonfacemove,from graphic
- 一个Python备份脚本,Python备份脚本,编写一个Python脚本
- 自己实现的2048,自己实现2048,# _*_utf-8_*
- 用Python配置JDK环境,Python配置JDK环境,#!usr\bin\en
- python3下载妹子图,你懂的。,python3妹子图,None
- 打印命令行参数,,#打印命令行参数#!/u
评论关闭