python-一個小爬蟲,爬取圖片


import re
import urllib.request
# 爬取網頁
def getHtml(url):
    page=urllib.request.urlopen(url)
    html=page.read()
    return html
# 獲取圖片地址
def getImg(html):
    rule=r'src="(.*?\.jpg)" width'
    rule_compile=re.compile(rule)
    Img_list=re.findall(rule_compile,html.decode('GBK'))
    return Img_list
url="http://desk.zol.com.cn/bizhi/7005_87014_2.html"
html=getHtml(url)
# print(getImg(html))
#  下載圖片到當前目錄
x=0
for i in getImg(html):
    urllib.request.urlretrieve(i,'%s爬蟲.jpg' % x)
    x+=1
 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM