吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3471|回复: 16
收起左侧

[Python 转载] 使用Python模拟登陆bilibili(过滑动验证)

[复制链接]
QingYi. 发表于 2021-6-21 17:54
首先需要验证码识别平台。 看代码。


官方文档上面有使用说明,可以琢磨一下。For free


和我之前的差不多,练练手

https://www.52pojie.cn/thread-1455857-1-1.html

----------------------------------------------------------------
没吃饭就抽个空出来把这个代码完善,刚刚完善完,就准备发吾爱来供大家参考

验证码识别失败的可以套try catch 循环什么的。 验证登录成功有什么信息即可(例如:个人中心)

直接给大家放成品好了。


loging_blbl.png


打码平台导入进来先
[Python] 纯文本查看 复制代码
#!/usr/bin/env python
# coding:utf-8

import requests
from hashlib import md5

class Chaojiying_Client(object):

    def __init__(self, username, password, soft_id):
        self.username = username
        password =  password.encode('utf8')
        self.password = md5(password).hexdigest()
        self.soft_id = soft_id
        self.base_params = {
            'user': self.username,
            'pass2': self.password,
            'softid': self.soft_id,
        }
        self.headers = {
            'Connection': 'Keep-Alive',
            'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
        }

    def PostPic(self, im, codetype):
        """
        im: 图片字节
        codetype: 题目类型 参考 [url=http://www.chaojiying.com/price.html]http://www.chaojiying.com/price.html[/url]
        """
        params = {
            'codetype': codetype,
        }
        params.update(self.base_params)
        files = {'userfile': ('ccc.jpg', im)}
        r = requests.post('http://upload.chaojiying.net/Upload/Processing.php', data=params, files=files, headers=self.headers)
        return r.json()

    def ReportError(self, im_id):
        """
        im_id:报错题目的图片ID
        """
        params = {
            'id': im_id,
        }
        params.update(self.base_params)
        r = requests.post('http://upload.chaojiying.net/Upload/ReportError.php', data=params, headers=self.headers)
        return r.json()


if __name__ == '__main__':
    # 用户中心>>软件ID 生成一个替换 96001
    chaojiying = Chaojiying_Client('username', 'password', '96001')
    # 本地图片文件路径 来替换 a.jpg 有时WIN系统须要//
    # im 图片的字节
    im = open('cap1.png', 'rb').read()
    print(chaojiying.PostPic(im, 9101))
#      {'err_no': 0, 'err_str': 'OK', 'pic_id': '1144813466470700019', 'pic_str': '185,71', 'md5': '2ce2a82ac54a1f0242cb896abb1c6c25'}





success_login_blbl.png


正菜
[Python] 纯文本查看 复制代码
import time
from PIL import Image
from selenium.webdriver import Chrome
from selenium.webdriver import ActionChains
from io import BytesIO

import chaojiying

browse = Chrome()

# 定义好超级鹰的账号密码
chaojiying = chaojiying.Chaojiying_Client('username', 'password', '918082')


# 可用这个方法去获取图片
def crop_image(image_file_name):
    # 截图
    # 定位你需要的元素 找到他
    img = browse.find_element_by_xpath("//div[@class='geetest_slicebg geetest_absolute']")
    # ver_img = browse.find_element_by_xpath("//div[@class='geetest_slicebg geetest_absolute']")
    location = img.location
    size = img.size
    print("图片的位置", location)
    print("图片的大小", size)
    # real location is 1071*391
    # get location is 1078*283
    top, buttom, left, right = location['y'], location['y'] + size['height'], location["x"], location["x"] + size[
        "width"]
    print("verify code location is : ", left, top, right, buttom)
    screenshot = browse.get_screenshot_as_png()
    screenshot = Image.open(BytesIO(screenshot))
    #  int  and   tuple
    capt = screenshot.crop((int(left), int(top), int(right), int(buttom)))
    capt.save(image_file_name)
    return capt


def login():
    url = "https://passport.bilibili.com/login"
    browse.get(url)
    # user and password of bilibili
    username = "123456"
    password = "54321"
    # 最大化
    browse.maximize_window()
    # find the name,password and login element and input data for click
    name_ele = browse.find_element_by_xpath("//input[@id='login-username']")
    pass_ele = browse.find_element_by_xpath("//input[@id='login-passwd']")
    login_ele = browse.find_element_by_xpath("//a[@class='btn btn-login']")
    name_ele.send_keys(username)
    pass_ele.send_keys(password)
    login_ele.click()
    # 鼠标放在滑动验证码的最左边
    time.sleep(5)
    # find slider element
    slider = browse.find_element_by_xpath("//div[@class='geetest_slider_button']")
    # 事件链
    ActionChains(browse).move_to_element(slider).perform()
    # 点了之后休息三秒
    time.sleep(3)

    # get verify code
    img1 = browse.find_element_by_xpath("//div[@class='geetest_slicebg geetest_absolute']")
    # get picture of gap ==> need ChaoJiYing
    dic = chaojiying.PostPic(img1.screenshot_as_png, 9101)
    # 从返回的值里面找到需要点击的下标
    res = dic['pic_str']
    print(res)
    # 分割 这里大家可以自己输出一下 就知道了
    # 28,110
    temp = res.split(",")
    # adjust data  ==> CJY return wrong dates,we should adjust it.  According to official documents
    # 9101         坐标选一,返回格式:x,y         15
    x = int(temp[0]) - 10
    y = int(temp[1])
    print("x is {}, y is {}".format(x, y))
    # 移动到某个区域 然后再进行点击
    # 然后找到区域 进行偏移
    # 是事件链
    # print("接下来的事件")
    # 按住不释放 ==> 拖动
    ActionChains(browse).click_and_hold(slider).perform()
    # only xoffset
    ActionChains(browse).move_by_offset(xoffset=x, yoffset=0).perform()
    time.sleep(2)
    # 释放 即可登录成功
    ActionChains(browse).release().perform()
    time.sleep(10)


if __name__ == '__main__':
    login()


免费评分

参与人数 3吾爱币 +9 热心值 +3 收起 理由
rhol + 1 + 1 用心讨论,共获提升!
hj170520 + 1 + 1 我很赞同!
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

侃遍天下无二人 发表于 2021-6-22 10:17
QingYi. 发表于 2021-6-22 10:15
是什么浏览器就导入什么内核 Firefox也可以

需要内核就证明有些算法你这边没模拟出来,借浏览器才完成了
 楼主| QingYi. 发表于 2021-6-22 10:21
侃遍天下无二人 发表于 2021-6-22 10:17
需要内核就证明有些算法你这边没模拟出来,借浏览器才完成了

???我这个就借助浏览器来做事的啊
deanyang 发表于 2021-6-21 18:29
fmamcn 发表于 2021-6-21 18:43
看的我都想学python 了
GiaoMan-wei 发表于 2021-6-21 19:16
试试selenium的click,,期待你的新作
 楼主| QingYi. 发表于 2021-6-21 19:21
GiaoMan-wei 发表于 2021-6-21 19:16
试试selenium的click,,期待你的新作

好的 马上在91上面更新
官本三竹 发表于 2021-6-21 19:49
厉害了大佬,回头试试
小三啦 发表于 2021-6-21 20:09
好家伙,一个比一个厉害
战火恐龙 发表于 2021-6-21 21:17
得抓紧学习python了
python在手,天下我有
侃遍天下无二人 发表于 2021-6-21 21:25
还需要chrome内核才能运行吗
jjl 发表于 2021-6-21 23:46
可以直接cookie登录吧
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-26 12:36

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表