python爬取圖片簡記

來源:互聯網
上載者:User

標籤:ret   dal   取圖   eth   mpi   log   bsp   span   htm   

參考:79506543

 1 # -*- coding:utf-8 -*- 2 import urllib 3 import urllib.request 4 import re 5  6 def getHtml(url): 7     request = urllib.request.Request(url) 8     response = urllib.request.urlopen(request) 9     html = response.read()10     return html11 12 def getImg(html):13     reg = ‘data-original="(.+?\.jpg)"‘     14     imgre = re.compile(reg)15     imglist = re.findall(imgre, html.decode(‘utf-8‘))16     localpath=‘G:/photo/‘17     x = 118     for imgurl in imglist  :19         urllib.request.urlretrieve(imgurl,localpath+‘%s.jpg‘ % x)  20         print(‘正在下載第%s張圖片‘ % x)21         x+=122         if x>20:                    23             break24     return None25 26 html = getHtml("https://www.zhihu.com/question/27364360")27 getImg(html)

 

python爬取圖片簡記

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.