Python爬蟲:爬取指定網址圖片

import re
import urllib.request
def gethtml(url):
    page=urllib.request.urlopen(url)
    html=page.read()
    return html
def getimg(html):
    reg = r'src="(.+?\.jpg)" width'
    img=re.compile(reg)
    html=html.decode('utf-8')#python3
    imglist=img.findall(gethtml("http://tieba.baidu.com/p/1753935195"))
    x = 0
    for imgurl in imglist:
        urllib.request.urlretrieve(imgurl,'%s.jpg'%x)
        x = x+1

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章