首页 > 编程语言 > 详细

python-简单爬虫抓取贴吧图片

时间:2017-01-17 10:37:40      阅读:271      评论:0      收藏:0      [点我收藏+]
一个简单的爬虫练习
import urllib.request
import re

def getHtml(url):
    page = urllib.request.urlopen(url)
    #read()返回的结果是二进制的需要转换成字符串
    html =page.read().decode("utf-8")
    return html

def getImage(page):

    reg=rsrc="(.+?\.jpg)" size
    imgre=re.compile(reg)
    print (imgre)
    imglist=re.findall(imgre,page)
    print (imglist)
    x=0
    for i in imglist:
        urllib.request.urlretrieve(i,%s.jpg %x)
        x+=1
    return imglist

html=getHtml("http://tieba.baidu.com/p/4721099001")
print(getImage(html))

 

python-简单爬虫抓取贴吧图片

原文:http://www.cnblogs.com/suye/p/6281615.html

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