python 爬取图片

思路分析:

​ requests 获得需要爬取的网页

​ 将爬取的网页数据做成BeautifulSoup

​ 应用soup 的API 找到需要的标签属性

通过标签属性获得二进制字节保存

1
2
3
4
5
6
7
8
9
10
11
12
13
import requests
from bs4 import BeautifulSoup

data = requests.get("url")
data.encoding = data.apparent_encoding

soup = BeautifulSoup(data.text)
link = soup.select_one("#container > div > div > div:nth-child(3) > div.list_con_box > div.zt_con_img > dl > dd > ul > li:nth-child(1) > a > img")['src']
f = open("D://a.jpg","wb")

pic_data = requests.get(link)
f.write(pic_data.content)
f.close()
Donate comment here