python批量下载色影无忌和蜂鸟的图片 爬虫小应用
来源:互联网 发布:sql server as用法 编辑:程序博客网 时间:2024/04/28 18:06
有些冗余信息,因为之前测试正则表达式,所以没有把它们给移走,不过不影响使用。
# -*- 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 url in all_url:if web_site_pattern.match(url):print 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'<img src="(.+?\.jpg)".+?/>')#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 <img atl=\"500\" src=\"www.qq.com/1.jpg\" width=\"700\"> asdfe aa<ima"p9=re.compile(r'<img .+ src="(.+)" .+>')urls=p9.findall(str2)#printprint urlsfor url in urls:print urlif __name__ =="__main__":#main()#download_pic_2()#regulation()download_pic()#getAllUrl()
#######后续
后面修改了代码,使用beautifulsoup,可以更大范围的下载图片
代码如下: http://www.30daydo.com/article/56
0 0
- python批量下载色影无忌和蜂鸟的图片 爬虫小应用
- python 爬虫批量下载图片
- Python爬虫的小白学习笔记1-批量下载图片
- 【Python】网络爬虫-批量下载图片
- 抓蜂鸟网站图片爬虫
- Python 3 爬虫之批量下载字帖图片
- 利用python网络爬虫批量下载花瓣中个人主页中收藏的所有图片
- Python实现简单爬虫功能--批量下载百度贴吧里的图片
- [python爬虫小实战2]根据用户输入关键词爬取今日头条图集,并批量下载图片
- python 爬虫下载图片
- python图片小爬虫
- python 图片小爬虫
- python爬虫(爬取蜂鸟网图片)_创建文件夹
- python爬虫(爬取蜂鸟网高像素图片)_空网页,错误处理
- Python批量下载图片
- python批量下载图片
- python 批量下载图片
- Python批量下载图片
- Android自定义系统分享面板
- This version of the rendering library is more recent than your version of ADT plug-in. Please update
- Sharepoint 2013 power view
- <P>作为第一篇博客</p>
- 详细讲解Android的图片下载框架UniversialImageLoader之磁盘缓存的扩展(二)
- python批量下载色影无忌和蜂鸟的图片 爬虫小应用
- List转数组,数组转List
- HTML中css和js链接中的版本号
- Android四种Activity的加载模式
- 数据结构小结
- Perl——二维数组
- 怎样成为PHP 方向的一个合格的架构师
- Eclipse默认标签TODO,XXX,FIXME和自定义标签[转]
- Android中实现日期时间选择器(DatePicker和TimePicker)