python 獲取網頁圖片 保存在本地

d2dn 9年前發布 | 1K 次閱讀 Python

import urllib
import string
import re
def getHtml(url):
    page=urllib.urlopen(url)
    html=page.read()
    return html
def getPic(html):
    imgre=re.compile(r'src=".+?.jpg" data-big-img')
    imglist=re.findall(imgre,html)
    print imglist
    x=0
    for imgurl in imglist:

    #src="http://www.xcxx.com/lld.jpg"'
    imgurl=imgurl.replace('src="','')
    imgurl=imgurl.replace('" data-big-img','')
    urllib.urlretrieve(imgurl,'%s.jpg' %x)
    x+=1

html=getHtml("http://www.xcxx.com/&quot;)</pre>

 本文由用戶 d2dn 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!