最近需要将某个网站的图片爬取下来,想尽了很多办法,后来使用python的爬虫技术将其爬取出来
import requests def download_save_img (img_url, file_name): headers ={ 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' } r = requests.get(img_url,headers=headers) f = open(file_name, mode="wb+") f.write(r.content) f.close() print(file_name + "已完成") base_url = 'xxxxxxxxxx' for i in range(0, 229): file_name = str(i) + '.jpg' img_url = base_url + file_name download_save_img(img_url, file_name)
标签:name,img,headers,Python,爬取,url,file,某个 From: https://www.cnblogs.com/PD-yin996649850/p/16920491.html