python 采集唯美girl
import requests;
import re;
import os;
# 1.请求网页
header = {
"user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"
}
response = requests.get("https://www.vmgirls.com/2957.html",headers=header)
# print(response.text)
html = response.text
# 2.解析网页
urls = re.findall("<img alt="(.*?)" .*?data-pagespeed-lsc-url="(.*?)".*?>",html)
dir_name = re.findall("<h1 class="post-title h3">(.*?)</h1>",html);
dir_name = dir_name[0]
if not os.path.exists(dir_name):
os.mkdir(dir_name)
# print(urls)
# print(dir_name)
# 3.保存图片
for url in urls:
file_name = url[1].split("/")[-1]
# print(file_name)
# print(url[1])
response = requests.get(url[1],headers=header)
with open(dir_name+"/"+file_name,"wb") as f:
f.write(response.content)
高颜值后台管理系统免费使用 ### 子枫后台管理系统 ###,可在宝塔面板直接安装
欢迎关注我的公众号:子枫的奇妙世界,获得独家整理的学习资源和日常干货推送。
如果您对我的其他专题内容感兴趣,直达我的个人博客:www.wangmingchang.com 。