您的位置:首页 > 编程语言 > Python开发

Python简单爬虫

2014-10-26 17:42 246 查看
简单Python爬虫,获得网页上的照片

#coding=utf-8

import urllib
import re

def getHtml(url):
page = urllib.urlopen(url)
html = page.read()
return html

def getImg(html):
reg = r'src="(.+?\.jpg)" pic_ext'
imgre = re.compile(reg)
imglist = re.findall(imgre, html)
return imglist

// 网站地址
url = "http://tieba.baidu.com/p/3368048910?pn=2"
html = getHtml(url)

listimg = getImg(html)
x = 0
for imgAddress in listimg:
print imgAddress
urllib.urlretrieve(imgAddress, 'image%s.jpg' % x)
x+=1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: