首页 > 其他 > 详细

简单爬虫-初次尝试

时间:2016-06-23 12:28:23      阅读:213      评论:0      收藏:0      [点我收藏+]
import urllib
import re
def getHtml(url):
    page = urllib.urlopen(url)
    html = page.read()
    return html
def getImg(html):
    reg = rsrc="(.+?\.jpg)" pic_ext
    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
url = "http://user.qzone.qq.com/645886209/4"
html = getHtml(url)  
print getImg(html)
urllib.urlretrieve(http://imgsrc.baidu.com/forum/w%3D580/sign=294db374d462853592e0d229a0ee76f2/e732c895d143ad4b630e8f4683025aafa40f0611.jpg,0.jpg)

 

简单爬虫-初次尝试

原文:http://www.cnblogs.com/Kermit-Li/p/5610062.html

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