python 爬取图片 Posted on 2021-02-14 思路分析: requests 获得需要爬取的网页 将爬取的网页数据做成BeautifulSoup 应用soup 的API 找到需要的标签属性 通过标签属性获得二进制字节保存 12345678910111213import requestsfrom bs4 import BeautifulSoupdata = requests.get("url")data.encoding = data.apparent_encodingsoup = 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 Donate WeChat Pay