首页 > 编程语言 > 详细

使用Python实现网站图片抓取

时间:2018-07-02 11:37:23      阅读:130      评论:0      收藏:0      [点我收藏+]
1,Python环境

技术分享图片

2,下面直接编写代码

import urllib
import re
import time

def getHtml(url):
page = urllib.urlopen(url)
html = page.read()
html = html.decode(‘utf-8‘)
return html

def getImgUrl(html):
str_re = r‘<img[^>]src[=\"\‘]+([^\"\‘])[\"\‘][^>]*>‘
imgre = re.compile(str_re,re.I)
imglist = re.findall(imgre,html)
for i in imglist:
urllib.urlretrieve(i,‘/mnt/test/‘+str(time.time())+".jpg")

#last setup is invocation and test it

html = getHtml(‘http://xxx.xxx.xxx‘)
getImgUrl(html)

使用Python实现网站图片抓取

原文:http://blog.51cto.com/13718210/2134963

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!