简单的python爬虫图片获取

时间:2021-03-16 14:08:34   收藏:0   阅读:0

# 图片爬取

import re
import urllib
import urllib.request

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

def getimg(html):
    reg = rsrc="(.*?\.jpg)"
    img=re.compile(reg)
    html=html.decode(utf-8) 
    imglist=re.findall(img,html)  
    x = 0
    for imgurl in imglist:
        urllib.request.urlretrieve(imgurl,D:\\迅雷下载\\%s.jpg%x)
        x = x+1    
if __name__ == "__main__":
    html=gethtml("http://pic.yxdown.com/list/0_0_1.html")#图片地址链接
    getimg(html)

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!