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

python3 爬虫 简单示例

2017-08-14 17:24 411 查看
#!/usr/local/python3/bin/python3
#coding:UTF-8
import urllib
import urllib.request#python3 later ...
import re

def getHtml(url):
page = urllib.request.urlopen(url)#python later ...
html = page.read()
return html

def getImg(html):
reg = r'src="(.+?\.jpg)" pic_ext'
imgre = re.compile(reg)
html=html.decode('utf-8')#python3 later...
imglist = re.findall(imgre,html)
x = 0
for imgurl in imglist:
urllib.request.urlretrieve(imgurl,'%s.jpg' % x)#python3 later ...
x+=1

html = getHtml("http://tieba.baidu.com/p/2460150866")

print(getImg(html))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python 爬虫