python-簡單爬蟲

來源:互聯網
上載者:User

標籤:bsp   內容   列表   讀取   pytho   div   Regex   import   int   

 1  #!/usr/bin/python 2 #coding=utf-8 3 #網路爬蟲 4 import urllib,re 5  6 def getHtml(url): 7     page=urllib.urlopen(url)  #開啟一個url 8     html=page.read()   #讀取全部內容產生一個字串(對象) 9     return html10 def getImg(html):11     reg=r‘src="(http://.+?\.jpg)"‘12     imgre=re.compile(reg)   #將一個Regex產生為響應的對象13     imglist=re.findall(imgre,html) #從html字串終止找到符合imgreRegex的項,返回列表14     print imglist15     x=016     for imgurl in imglist:17         urllib.urlretrieve(imgurl,‘%s.jpg‘%x)18         x+=119 20 html=getHtml(‘http://tieba.baidu.com/p/4710048390‘)21 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.