天天看點

Python爬蟲很難?10行代碼寫一個最簡單的圖檔爬蟲

前言

受害網站

http://www.win4000.com/meinv197522_3.html      
Python爬蟲很難?10行代碼寫一個最簡單的圖檔爬蟲

開始代碼

導入工具

import re
import requests      

請求網頁,得到html

index_url = 'http://www.win4000.com/meinv197522_3.html'
response = requests.get(index_url)
print(response.text)
r = re.findall('<img class="pic-large" src="http://static.win4000.com/home/images/placeholder.jpg" data-original="(.*?)" url=".*?" />', response.text, re.S)
image_url = r[0]      

下載下傳圖檔儲存到本地

image_response = requests.get(image_url)
image_name = image_url.split('/')[-1]      

圖檔 視訊 音頻 都是二進制 暫時先記住

with open(image_name, mode='wb') as f:
    # content 内容
    f.write(image_response.content)