import requests;
import re;
import os;
import parsel;
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.doutula.com/photo…’,headers=header)
html = response.text
2. 解析网页
selector = parsel.Selector(html)
print(selector)
dir_name = ‘doutu_list’
if not os.path.exists(dir_name):
os.mkdir(dir_name)
result_list = selector.xpath(‘//a[@class=”col-xs-6 col-sm-3″]’)
for result in result_list:
title = result.xpath('./img/@alt').get()
img_url = result.xpath('./img/@data-original').get()
ext = img_url.split('.')[-1]
file_name = title+'.'+ext
print(title,img_url)
# 保留
response = requests.get(img_url,headers=header)
with open(dir_name+'/'+file_name,'wb') as f:
f.write(response.content)
高颜值后盾管理系统收费应用 ### 子枫后盾管理系统 ###,可在宝塔面板间接装置
欢送关注我的公众号:子枫的微妙世界,取得独家整顿的学习资源和日常干货推送。
如果您对我的其余专题内容感兴趣,中转我的集体博客:www.wangmingchang.com。