简单的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)

 

上一篇:python 爬虫基础


下一篇:python爬虫基础之urllib