python3 爬取小姐姐图片

使用python3直接运行即可,可以自己切换url

import requests
import re
import time
import os
# 模仿浏览器访问
headers = {
    'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36'
}
#网站地址
response = requests.get('https://www.vmgirls.com/13138.html',headers=headers)
html = response.text
#提取图片标题
dir_name = re.findall('

(.*?)

',html)[-1] #判断文件夹是否存在 if not os.path.exists(dir_name): os.mkdir(dir_name) #爬取图片地址 urls = re.findall('',html) print(urls) for url in urls: #提取图片名字 file_name = url.split('/')[-1] response = requests.get(url,headers=headers) #新建文件夹以图片标题命名,并保存图片 with open(dir_name + '/' + file_name,'wb')as f: f.write(response.content)

你可能感兴趣的:(python3 爬取小姐姐图片)