您的位置:首页 > 理论基础 > 计算机网络

python中使用网络爬虫下载图片

2014-03-24 16:07 781 查看
import re

import urllib  

  

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 = imgre.findall(html)  

    x = 0  

    for imgurl in imglist:  

        urllib.urlretrieve(imgurl,'%s.jpg' % x)  

        x = x + 1          

     

html = getHtml("http://tieba.baidu.com/p/2460150866")  

getImg(html)  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python 网络爬虫 图片