python urlretrieve 下載圖片

來源:互聯網
上載者:User

標籤:3ds   AC   路徑   data   資料   icons   line   直接   sign   

python 3中urlretrieve方法直接將遠端資料下載到本地.為什麼不行? 55 import re import urllib.request def getHtml(url): page = urllib.request.urlopen(url) html = page.read() return html def getImg(html): html = html.decode(‘GBK‘) reg = r‘src="(.*?\.jpg)" width‘... 展開   默_____契 | 瀏覽 20538 次 | 舉報 我有更好的答案  2018-02-02  最佳答案  

你的路徑可能不對,按照My Code,你需要在d盤根目錄下建立一個test檔案夾,才能正常運行

我把代碼附上:

import reimport urllib.request def Schedule(a,b,c):       per = 100.0 * * / c       if per>100:           per = 100           print(‘完成!‘)       print(‘%.2f%%‘ % per)def getHtml(url):       page = urllib.request.urlopen(url)       html = page.read()       return html def getImg(html):       html = html.decode(‘utf-8‘)       reg = r‘src="(.*?\.jpg)" width‘       imgre = re.compile(reg)       imglist = imgre.findall(html)       = 0       for imgurl in imglist:              #  寫好你的路徑              urllib.request.urlretrieve(imgurl,‘D:\\test\\%s.jpg‘ % x,Schedule)              += 1 html = getHtml(‘http://tieba.baidu.com/p/741081023‘)print(getImg(html))

運行結果:

python urlretrieve 下載圖片

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.