简单爬虫-初次尝试

import urllib
import re
def getHtml(url):
    page = urllib.urlopen(url)
    html = page.read()
    return html
def getImg(html):
    reg = r'src="(.+?\.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')

 

posted on 2016-06-23 11:18  Kermit.Li  阅读(112)  评论(0)    收藏  举报

导航