大旗谷资源网 Design By www.zqyou.com
写在前面
作为一名找不到工作的爬虫菜鸡人士来说,登陆这一块肯定是个比较大的难题。
从今天开始准备一点点对大型网站进行逐个登陆破解。加深自己爬虫水平。
环境搭建
- Python 3.7.7环境,Mac电脑测试
- Python内置库
- 第三方库:rsa、urllib、requests
PC端登陆
全部代码:
'''PC登录哔哩哔哩'''
class Bilibili_For_PC():
def __init__(self, **kwargs):
for key, value in kwargs.items(): setattr(self, key, value)
self.session = requests.Session()
self.__initialize()
'''登录函数'''
def login(self, username, password, crack_captcha_func=None, **kwargs):
# 若参数中给入代理,则设置
self.session.proxies.update(kwargs.get('proxies', {}))
# 是否需要验证码
is_need_captcha = False
while True:
# 需要验证码
if is_need_captcha:
captcha_img = self.session.get(self.captcha_url, headers=self.captcha_headers).content
data = {'image': base64.b64encode(captcha_img).decode('utf-8')}
captcha = self.session.post(self.crack_captcha_url, json=data).json()['message']
# 获得key值
appkey = '1d8b6e7d45233436'
data = {
'appkey': appkey,
'sign': self.__calcSign('appkey={}'.format(appkey))
}
response = self.session.post(self.getkey_url, data=data)
response_json = response.json()
key_hash = response_json['data']['hash']
pub_key = rsa.PublicKey.load_pkcs1_openssl_pem(response_json['data']['key'].encode('utf-8'))
# 模拟登录
if is_need_captcha:
data = "access_key=&actionKey=appkey&appkey={}&build=6040500&captcha={}&challenge=&channel=bili&cookies=&device=pc&password={}&permission=ALL&seccode=&subid=1&ts={}&username={}&validate=" .format(appkey, captcha, urllib.parse.quote_plus(base64.b64encode(rsa.encrypt('{}{}'.format(key_hash, password).encode(), pub_key))), int(time.time()), urllib.parse.quote_plus(username))
else:
data = "access_key=&actionKey=appkey&appkey={}&build=6040500&captcha=&challenge=&channel=bili&cookies=&device=pc&password={}&permission=ALL&seccode=&subid=1&ts={}&username={}&validate=" .format(appkey, urllib.parse.quote_plus(base64.b64encode(rsa.encrypt('{}{}'.format(key_hash, password).encode(), pub_key))), int(time.time()), urllib.parse.quote_plus(username))
data = "{}&sign={}".format(data, self.__calcSign(data))
response = self.session.post(self.login_url, data=data, headers=self.login_headers)
response_json = response.json()
# 不需要验证码, 登录成功
if response_json['code'] == 0 and response_json['data']['status'] == 0:
for cookie in response_json['data']['cookie_info']['cookies']:
self.session.cookies.set(cookie['name'], cookie['value'], domain='.bilibili')
print('[INFO]: Account -> %s, login successfully' % username)
infos_return = {'username': username}
infos_return.update(response_json)
return infos_return, self.session
# 需要识别验证码
elif response_json['code'] == -105:
is_need_captcha = True
# 账号密码错误
elif response_json['code'] == -629:
raise RuntimeError('Account -> %s, fail to login, username or password error' % username)
# 其他错误
else:
raise RuntimeError(response_json.get('message'))
'''计算sign值'''
def __calcSign(self, param, salt="560c52ccd288fed045859ed18bffd973"):
sign = hashlib.md5('{}{}'.format(param, salt).encode('utf-8'))
return sign.hexdigest()
'''初始化'''
def __initialize(self):
# 登陆请求头
self.login_headers = {'Content-type': 'application/x-www-form-urlencoded'}
# 破解验证码请求头
self.captcha_headers = {'Host': 'passport.bilibili.com'}
# 获取key密钥URL
self.getkey_url = 'https://passport.bilibili.com/api/oauth2/getKey'
# 获取登陆URL
self.login_url = 'https://passport.bilibili.com/api/v3/oauth2/login'
# 获取验证码URL
self.captcha_url = 'https://passport.bilibili.com/captcha'
# 破解网站来自: https://github.com/Hsury/Bilibili-Toolkit
# 破解验证码URL
self.crack_captcha_url = 'https://bili.dev:2233/captcha'
# 请求头都得加这个
self.session.headers.update({'User-Agent': "Mozilla/5.0 BiliDroid/5.51.1 (bbcallen@gmail.com)"})
移动端登陆
移动端与PC端类似,网址URL差异以及请求头差异。在此不过多介绍。
全部代码:
'''移动端登录B站'''
class Bilibili_For_Mobile():
def __init__(self, **kwargs):
for key, value in kwargs.items(): setattr(self, key, value)
self.session = requests.Session()
self.__initialize()
'''登录函数'''
def login(self, username, password, crack_captcha_func=None, **kwargs):
self.session.proxies.update(kwargs.get('proxies', {}))
# 是否需要验证码
is_need_captcha = False
while True:
# 需要验证码
if is_need_captcha:
captcha_img = self.session.get(self.captcha_url, headers=self.captcha_headers).content
data = {'image': base64.b64encode(captcha_img).decode('utf-8')}
captcha = self.session.post(self.crack_captcha_url, json=data).json()['message']
# 获得key值
appkey = 'bca7e84c2d947ac6'
data = {
'appkey': appkey,
'sign': self.__calcSign('appkey={}'.format(appkey))
}
response = self.session.post(self.getkey_url, data=data)
response_json = response.json()
key_hash = response_json['data']['hash']
pub_key = rsa.PublicKey.load_pkcs1_openssl_pem(response_json['data']['key'].encode('utf-8'))
# 模拟登录
if is_need_captcha:
data = "access_key=&actionKey=appkey&appkey={}&build=6040500&captcha={}&challenge=&channel=bili&cookies=&device=phone&mobi_app=android&password={}&permission=ALL&platform=android&seccode=&subid=1&ts={}&username={}&validate=" .format(appkey, captcha, urllib.parse.quote_plus(base64.b64encode(rsa.encrypt('{}{}'.format(key_hash, password).encode(), pub_key))), int(time.time()), urllib.parse.quote_plus(username))
else:
data = "access_key=&actionKey=appkey&appkey={}&build=6040500&captcha=&challenge=&channel=bili&cookies=&device=phone&mobi_app=android&password={}&permission=ALL&platform=android&seccode=&subid=1&ts={}&username={}&validate=" .format(appkey, urllib.parse.quote_plus(base64.b64encode(rsa.encrypt('{}{}'.format(key_hash, password).encode(), pub_key))), int(time.time()), urllib.parse.quote_plus(username))
data = "{}&sign={}".format(data, self.__calcSign(data))
response = self.session.post(self.login_url, data=data, headers=self.login_headers)
response_json = response.json()
# 不需要验证码, 登录成功
if response_json['code'] == 0 and response_json['data']['status'] == 0:
for cookie in response_json['data']['cookie_info']['cookies']:
self.session.cookies.set(cookie['name'], cookie['value'], domain='.bilibili')
print('[INFO]: Account -> %s, login successfully' % username)
infos_return = {'username': username}
infos_return.update(response_json)
return infos_return, self.session
# 需要识别验证码
elif response_json['code'] == -105:
is_need_captcha = True
# 账号密码错误
elif response_json['code'] == -629:
raise RuntimeError('Account -> %s, fail to login, username or password error' % username)
# 其他错误
else:
raise RuntimeError(response_json.get('message'))
'''计算sign值'''
def __calcSign(self, param, salt="60698ba2f68e01ce44738920a0ffe768"):
sign = hashlib.md5('{}{}'.format(param, salt).encode('utf-8'))
return sign.hexdigest()
'''初始化'''
def __initialize(self):
self.login_headers = {
'Content-type': 'application/x-www-form-urlencoded'
}
self.captcha_headers = {
'Host': 'passport.bilibili.com'
}
self.getkey_url = 'https://passport.bilibili.com/api/oauth2/getKey'
self.login_url = 'https://passport.bilibili.com/api/v3/oauth2/login'
self.captcha_url = 'https://passport.bilibili.com/captcha'
# 破解网站来自: https://github.com/Hsury/Bilibili-Toolkit
self.crack_captcha_url = 'https://bili.dev:2233/captcha'
self.session.headers.update({'User-Agent': "Mozilla/5.0 BiliDroid/5.51.1 (bbcallen@gmail.com)"})
大旗谷资源网 Design By www.zqyou.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
大旗谷资源网 Design By www.zqyou.com
暂无Python爬虫破解登陆哔哩哔哩的方法的评论...
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。
更新日志
2025年11月23日
2025年11月23日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]