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
 
相關文章
相關標籤/搜索