栏目分类:
子分类:
返回
文库吧用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
文库吧 > IT > 软件开发 > 后端开发 > Python > python爬虫

python过【安全检查! | 百度云加速】的解决方案

python爬虫 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python过【安全检查! | 百度云加速】的解决方案

首先假设我们还不知道网站有百度云加速检查,先直接获取。网址因某些原因屏蔽,但是不影响整体思路

shareurl = 'https:**************************'
headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
}
response = httpx.get(shareurl, headers=headers)
cookie = response.headers['set-cookie'].split(';')[0]
ray = response.headers['cf-ray'].split('-')[0]
posturl = '/'.join(shareurl.split('/')[:3])+html.unescape(re.findall('(?<=action=").+?(?=")', response.text)[0])
r = re.findall('(?<=value=").+?(?=")', response.text)[0]
url = 'https://captcha.su.baidu.com/session_cb?pub=377e4907e1a3b419708dbd00df9e8f79'
headers = {
    'Host': 'captcha.su.baidu.com',
    'Referer': shareurl,
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'
}
response = httpx.get(url, headers=headers).text
session = response.split('"')[-2]
url = 'https://captcha.su.baidu.com/image?session='+session+'&pub=377e4907e1a3b419708dbd00df9e8f79'
response = httpx.get(url, headers=headers).content
with open('验证码.jpg', 'wb') as f:
    f.write(response)
yanzhengma = input('请输入同目录下的验证码:')
headers = {
    'content-type': 'application/x-www-form-urlencoded',
    'cookie': cookie,
    'referer': shareurl,
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
}
data = {
    'r': r,
    'id': ray,
    'captcha_challenge_field': session,
    'manual_captcha_challenge_field': yanzhengma,
}
response = httpx.post(posturl, headers=headers, data=data)
print(response.text)


转载请注明:文章转载自 www.wk8.com.cn
本文地址:https://www.wk8.com.cn/it/740152.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 wk8.com.cn

ICP备案号:晋ICP备2021003244-6号