Python中運用正則表達式抓取網頁圖片

#!/usr/bin/python
import re
import urllib

#獲取網頁信息
def getHtml(url):
    page = urllib.urlopen(url)
    html = page.read()
    return html
def getImg(html):

#匹配網頁中的圖片  

  reg = r'src="(.*?\.jpg)" alt'

    imgre = re.compile(reg)
    imglist = re.findall(imgre,html)
    x = 0
    for imgurl in imglist:
        urllib.urlretrieve(imgurl,'%s.jpg' % x)
        x+=1




html = getHtml("http://photo.bitauto.com/?WT.mc_id=360tpdq")
print getImg(html)
發佈了24 篇原創文章 · 獲贊 9 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章