python实现美空图片抓取机器人
来源:互联网 发布:编程网站推荐 编辑:程序博客网 时间:2024/04/27 00:01
最近挺闲,没事逛美空看美女,忽然觉得为什么不把照片都下到本地,没事的时候慢慢看呢,于是就有了以下代码:
#-*- coding:utf-8 -*-
import urllib
import re
import os
#IMG_REG = re.compile('<img[^>]*?src[^>]*?=[\"\'][^"]*?[\'\"]')
IMG_REG = re.compile('<img[^>]*?src2=[\"\'][^"]*?[\'\"]')
URL_REG = re.compile('<a href="(.*?)" title="(.*?)" hidefocus="true" target="_blank">')
LOCAL_DIR = 'c://tmp/pictrue/'
def cbk(a, b, c):
per = 100 * a * b / c
if per > 100:
per = 100
print '%.2f%%' % per
def getPictrueFromOnePage(url, dirPath):
file = urllib.urlopen(url)
content = file.read()
for match in IMG_REG.findall(content):
print match
imgurl = match[match.index("http"):][:-1]
filename = imgurl[imgurl.rindex("/") + 1:]
print imgurl
print filename
local = dirPath + filename
urllib.urlretrieve(imgurl, local, cbk)
def mainPorcess(url):
content = urllib.urlopen(url).read()
i = 0
for matched in URL_REG.findall(content):
i = i + 1
subUrl = 'http://www.moko.cc' + matched[0]
print subUrl
path = LOCAL_DIR + matched[1].decode('utf-8').encode('gbk') + '\\'
if not os.path.isdir(path):
try:
os.mkdir(path)
except Exception as e:
path = LOCAL_DIR + str(i) + '\\'
print path
getPictrueFromOnePage(subUrl, path)
if __name__ == '__main__':
mainPorcess('http://www.moko.cc/channels/post/23/1.html')
它能自动下载照片并以美女的名字生成文件夹来存贮照片。
这个程序有几个缺陷:
1. 只能抓取美空页面中按照美女姓名分类的二级目录下的照片。
2. 只能抓取当前页,不能自动翻页
最后再说一句,python真是巨方便!!!
- python实现美空图片抓取机器人
- python 实现网站图片抓取小爬虫
- python实现批量图片的抓取
- python实现简单爬虫抓取图片
- Scrap学习笔记 --- python实现抓取图片
- Python 实现简单的网络抓取图片
- python抓取网页图片
- Python抓取图片
- python图片抓取
- python爬虫抓取图片
- python抓取网页图片
- python抓取百度图片
- Python抓取图片Demo
- Python 抓取图片示例
- Python多线程抓取图片
- python抓取图片示例
- python美女图片抓取
- Python抓取网页图片
- ATV2常见问题
- Friend's Video List
- container_of()宏
- container_0f 2
- PL/SQL-1 块的使用
- python实现美空图片抓取机器人
- 186. Great minds think alike. 英雄之见略同
- 员工没有斗志了怎么办
- 一日一点RakNet(16)--BitStream
- wxsqlite 加解密
- 如何使用js来获取cookie的值
- 挂了羊头就要卖羊肉
- DS18B20温度传感器完整C程序
- DES的代码,因为是用QT写的。所以说直接复制粘贴是不能运行的啊。