简单的python爬虫图片获取

# 图片爬取

import re
import urllib
import urllib.request

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

def getimg(html):
    reg = r'src="(.*?\.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)

 

posted @ 2021-03-15 15:00  outsider078  阅读(112)  评论(0)    收藏  举报