简单爬虫-初次尝试

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')
原文地址:https://www.cnblogs.com/Kermit-Li/p/5610062.html