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

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 9439|回复: 33
收起左侧

[Python 转载] 【python爬虫】原神公测预抽卡活动自动化抽卡脚本

  [复制链接]
a13381041 发表于 2020-9-14 11:40
本帖最后由 a13381041 于 2020-9-14 11:42 编辑

9月15号原神开始公测,公测时出了一个公测预抽卡活动,玩家可以通过这个活动,免费获取一些武器,而我总会忘记去抽,所以写个脚本偷下懒。我将写好的脚本打包成了exe,解压压缩包,运行crawl.exe,输入手机和验证码就可以自动翻卡。
程序压缩包:下载:https://www.lanzoux.com/ikPLZglwnjg 密码:1y64


活动链接:https://webstatic.mihoyo.com/ys/event/e20200829/index.html
1600054776(1).jpg
程序运行图片
1600054949(1).jpg
1600051412(1).jpg

以下是爬取的代码

[Python] 纯文本查看 复制代码
import requests
import json

class Crawl():
    #初始化cookies
    def __init__(self):
        self.login_ticket = "";
        self.account_id="";
        self.login_uid="";
        self.cookie_token="";

    #get请求
    def get(self,url):
        payload = {}
        headers = {
            'Cookie': 'login_uid='+self.login_uid+'; account_id='+self.account_id+'; login_ticket='+self.login_ticket+'; cookie_token='+self.cookie_token,
        }
        response = requests.request("GET", url, headers=headers, data = payload)
        return json.loads(response.text)
    #post请求
    def post(self,url,data):
        headers = {
            'Cookie': 'login_uid='+self.login_uid+'; account_id='+self.account_id+'; login_ticket='+self.login_ticket+'; cookie_token='+self.cookie_token
        }
        response = requests.request("POST", url, headers=headers, data = data)
        return json.loads(response.text)

    def post2(self,url):
        headers = {
            'Cookie': 'login_uid='+self.login_uid+'; account_id='+self.account_id+'; login_ticket='+self.login_ticket+'; cookie_token='+self.cookie_token
        }
        response = requests.request("POST", url, headers=headers, data = {})
        return json.loads(response.text)

    #获取以获得的物品
    def item_list(self):
        url = "https://api-takumi.mihoyo.com/event/e20200828bingo/item_list"
        res = self.get(url)
        return res

    #分享
    def share(self):
        url = "https://api-takumi.mihoyo.com/event/e20200828bingo/share"
        res = self.get(url)
        return res


    #获取基本信息,是否分享,还剩翻卡次数
    def home(self):
        url ="https://api-takumi.mihoyo.com/event/e20200828bingo/home"
        res = self.get(url)
        return res

    #获取验证码
    def getCaptcha(self,mobile):
        body ={"action_type":"login","t":"1599809011444","mobile":mobile}
        url = "https://webapi.account.mihoyo.com/Api/create_mobile_captcha";
        res = self.post(url,body)
        return res

    def login(self,mobile,captcha):
        body ={"mobile_captcha":captcha,"is_bh2":"false","action_type":"login","t":"1599809011444","mobile":mobile}
        url = "https://webapi.account.mihoyo.com/Api/login_by_mobilecaptcha";
        headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36',
        }
        session = requests.session()
        response = session.post(url, headers=headers, data = body)
        res = json.loads(response.text)
        if(res["code"] == 200 and res["data"]['status'] == 1 ):
            self.login_ticket = str(res["data"]['account_info']['weblogin_token']) ;
            self.account_id= str(res["data"]['account_info']['account_id']);
            self.login_uid= str(res["data"]['account_info']['account_id']);

            cookies_url =  "https://webapi.account.mihoyo.com/Api/cookie_accountinfo_by_loginticket?t=1599809011444&login_ticket="+res["data"]['account_info']['weblogin_token']
            headers = {
                'Cookie': 'login_uid='+self.login_uid+'; account_id='+self.account_id+'; login_ticket='+self.login_ticket
            }
            response = session.get(cookies_url, headers=headers)
            cookies_res = json.loads(response.text)
            self.cookie_token= str(cookies_res["data"]['cookie_info']['cookie_token']);


    def gameinfo(self,flag):
        url = "https://api-takumi.mihoyo.com/event/e20200828bingo/"+flag
        if(flag == 'start'):
            res = self.post(url,{})
        else:
            res = self.get(url)
        return res['data']['game_id']

    def click(self,game_id):
        sum = 0
        for i in range(9):
            url = "https://api-takumi.mihoyo.com/event/e20200828bingo/next?game_id="+str(game_id)+"&index="+str(i);
            res = self.post2(url)
            if res["message"] == "OK":
                sum +=1
        if sum == 9:
            print("本轮翻卡完毕")

if __name__ == '__main__':
    #主程序
    crawl = Crawl()
    # 登录
    print("开始登录————")
    mobile = input("请输入手机号码:")
    print("开始获取验证码————")
    print(crawl.getCaptcha(mobile))
    captcha = input("请输入验证码:")
    crawl.login(mobile,captcha)

    #分享
    homeRes = crawl.home()
    nowday_share_cnt = homeRes['data']['nowday_share_cnt']
    if nowday_share_cnt == 0:
        print("开始分享————")
        print(crawl.share())

    #获取基本信息
    print("获取基本信息————")
    homeRes = crawl.home()
    print(homeRes)
    lucky = homeRes['data']['lucky']
    chance = homeRes['data']['chance']
    print("当前幸运值:"+str(lucky))
    print("可抽卡数:"+str(chance))

    word = None
    while word != "":
        word = input("是否进行翻卡,继续请输入回车,退出请直接关闭")

    if chance == 0:
        print("您今天的抽卡已经到达上限,请次日再来")
        word = None
        while word != "":
            word = input("您的今日的翻卡完毕,请输入回车关闭程序")
        exit()



    print("开始翻卡————")
    new_round = homeRes['data']['new_round']
    for index in range(chance):
        print("开始第"+str(index+1)+"次翻卡")
        if new_round == True:
            flag = "start"
            game_id = crawl.gameinfo(flag)
            crawl.click(game_id)
        else:
            flag = "game_info"
            game_id = crawl.gameinfo(flag)
            crawl.click(game_id)

    word = None
    while word != "":
        word = input("您的今日的翻卡完毕,请输入回车关闭程序")



链接.txt

44 Bytes, 下载次数: 113, 下载积分: 吾爱币 -1 CB

免费评分

参与人数 6吾爱币 +9 热心值 +6 收起 理由
asq56747277 + 1 + 1 我很赞同!
某七 + 1 ganxiefenxiang
苏紫方璇 + 5 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
凉意人 + 1 + 1 用心讨论,共获提升!
A-Wood + 1 + 1 谢谢@Thanks!
千熙颜 + 1 + 1 我很赞同!

查看全部评分

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

 楼主| a13381041 发表于 2020-9-17 08:41
已更新为一小时免登陆版,请移步:https://www.52pojie.cn/thread-1267703-1-1.html
 楼主| a13381041 发表于 2020-9-21 10:24
lzawww 发表于 2020-9-21 07:21
请问是如何找到这些服务器接口的?有什么快捷方法吗?

打开活动页面,打开浏览器的调试模式,然后每次点击都是请求,看他的请求报文,自己分析
 楼主| a13381041 发表于 2020-9-15 15:26
草飞天下 发表于 2020-9-15 08:36
我也是自学的,我在pycharm上是跑不起来的,那些分号是报语法错误,你有了解过Python官方的语法吗?你可 ...

应该是你的pycharm的语法校验没有设置好吧,你试试把分号什么的删除看看。
理论来说我的代码能被python编译并且可以运行语法应该是没啥问题的,不然也运行不了,编译的内核都python3,没道理我的可以跑,你不能运行。所以我猜应该是pycharm的语法校验没有设置好,我之前写vue的时候也是没把vue的语法校验设好,结果代码是没毛病的,但是就是总爆红
861078848 发表于 2020-9-14 11:48
没有python环境可以运行吗
 楼主| a13381041 发表于 2020-9-14 11:49
861078848 发表于 2020-9-14 11:48
没有python环境可以运行吗

应该可以,你用打包好的exe试试
 楼主| a13381041 发表于 2020-9-14 11:53
861078848 发表于 2020-9-14 11:48
没有python环境可以运行吗

我试过,没有python环境可以跑
tangxiaobin 发表于 2020-9-14 12:05
感谢楼下辛苦分享
chinaxhb 发表于 2020-9-14 12:20
不错正好可以学习一下PYTHON的爬虫的写法
a109416 发表于 2020-9-14 12:26
感觉好像有点小问题呀,我手动打开活动页面是有翻拍次数的,但是脚本提示0没有次数
lishang0808 发表于 2020-9-14 13:50
win10 可以用 不需要Python环境
XiaoBaizzZ 发表于 2020-9-14 14:00
大佬牛逼
Tiana丶Tiana 发表于 2020-9-14 14:01
楼主,我们可以组队了
您需要登录后才可以回帖 登录 | 注册[Register]

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

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

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

GMT+8, 2024-6-1 11:53

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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