python下载图片

import re
import  urllib.request  

def getHtml(url):
    page = urllib.request.urlopen(url)
    html = page.read()
    return str(html)

def getImg(html):
    reg = r'src="(.+?\.jpg)" pic_ext'
    imgre = re.compile(reg)
    imglist = re.findall(imgre,html)
    return imglist      
   
html = getHtml("http://tieba.baidu.com/p/2460150866")
print getImg(html)
posted @ 2015-02-03 21:56  小毛驴  阅读(223)  评论(0编辑  收藏  举报