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

python 爬虫入门1 网页图片保存

2017-01-17 17:20 866 查看

coding=utf-8#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)”’

imgre = re.compile(reg)

imglist = re.findall(imgre,html)

x = 0

for imgurl in imglist:

urllib.urlretrieve(imgurl,’%s.jpg’ % x)

x+=1

return imglist

html = getHtml(“http://www.cocoachina.com/bbs/read.php?tid=182334&page=1“)

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