python抓取性感尤物美女图
2016-05-05 08:39
585 查看
由于是只用标准库,装了python3运行本代码就能下载到多多的美女图...
写出代码前面部分的时候,我意识到自己的函数设计错了,强忍继续把代码写完。
测试发现速度一般,200K左右的下载速度,也没有很好的错误处理。不过还是基本上能用。以后继续改进。
写出抓取东西的程序,比写其它程序要开心很多。^_^,大家也来试试写一个?
写出代码前面部分的时候,我意识到自己的函数设计错了,强忍继续把代码写完。
测试发现速度一般,200K左右的下载速度,也没有很好的错误处理。不过还是基本上能用。以后继续改进。
写出抓取东西的程序,比写其它程序要开心很多。^_^,大家也来试试写一个?
""" python抓取性感尤物美女图.py 2016年5月4日 00:51:00 codegay 参考资料: Python3学习笔记(urllib模块的使用) http://www.cnblogs.com/Lands-ljk/p/5447127.html 以下例子是python2的代码,并且用到lxml,requests 库 我用python3标准库和正则写一个下载全站美女图的程序 使用python来批量抓取网站图片 http://www.cnblogs.com/TeyGao/p/5225940.html """ print("程序运行中...") import re from urllib import request import os from pprint import pprint from time import sleep rooturl="http://www.xgyw.cc/" def getclass(): rec=re.compile('''align=center\>\<a href="(/\w+/)\"\>(.+)\</a\>''') try: txt=request.urlopen(rooturl).read().decode("gbk") fl=rec.findall(txt) except: print("错误") sleep(1) print("分类:") pprint(fl) return fl fenlei=getclass()#下载所有分类下的图片 #fenlei=[getclass()[-1]]#只下载推女郎 def getpagelist(): plist=[] for f,n in fenlei: rec=re.compile('''({}page_\d+?\.html)'''.format(f)) try: txt=request.urlopen(rooturl+f).read().decode("gbk") t=sorted(set(rec.findall(txt)+[f])) plist+=t except: print("错误",e) sleep(1) #print("page_list:") #pprint(plist) return plist pagelist=getpagelist() def getalbumlist(): albumlist=[] for r in pagelist: print(rooturl+r) try: txt=request.urlopen(rooturl+r).read().decode("gbk") for x in re.findall(r'''href=(/(\w+)/(\2)\d+.html)''',txt): albumlist+=[x[0]] except: print("getalbumlist错误") sleep(1) return albumlist albumlist=getalbumlist() def getfphoto(): for r in albumlist: try: txt=request.urlopen(rooturl+r).read().decode("gbk") result=re.findall(r'''(/(\w+)/(\2)\d+_?\d*.html)''',txt) except: sleep(1) pass for x in result: try: html=request.urlopen(rooturl+x[0]).read().decode("gbk") jpgresult=re.findall('''src=\"(/uploadfile.*?\d+/\w+\.jpg)\"''',html) print(jpgresult) except: sleep(1) for h in jpgresult: try: request.urlretrieve(rooturl+h,os.path.basename(h)) except: print(3) sleep(1) getfphoto()
相关文章推荐
- python之路之正则表达式
- 模块间的调用
- python2.7.x的字符串编码到底什么鬼?(中文和英文的处理)
- python 大小写转换函数
- 【Python】【辅助程序】练手小程序:记录外网动态IP地址
- Python 迭代器和生成器
- 关于python的for语句
- libpython2.7.so.1.0 cannot open的解决方法
- 使用Python判断质数(素数)的简单方法讲解
- Python环境下搭建属于自己的pip源的教程
- Python使用Paramiko模块编写脚本进行远程服务器操作
- Python中内建函数的简单用法说明
- Python核心编程-第五章
- python 错误、异常
- python 测试与调试(test)
- Python爬虫: 抓取One网页上的每日一话和图
- python的json模块,针对decimal类型直接dumps报错
- Python文件读写基础
- Python 类与元类的深度挖掘 II
- Python-量化分析之路