根据大佬的代码,摸索了阿里云函数部署流程,过程和微调后的代码如下

经验创意 · 436 次浏览
Fang-L 创建于 2024-04-24 17:17
  1. 注册阿里云
    并打开创建云函数界面,网址和界面如下
    1. 网址:函数计算 FC (aliyun.com)
    2. 选择创建“事件函数”,设置如下红框所示,其余选项不必更改
    3. 拉倒页面最下方,点击“创建”
    4. 将框中的代码删除,替换为文末的代码,记得更改下列内容
        "username": "填写你的用户名",
        "password": "填写你的密码",
      点击“部署代码”并“测试函数”
    5. 代码反馈“执行成功”,则函数运行成功,点击日志输出也可查看输出信息

    6. 设置每日自动运行,即自动签到,按红框顺序指引创建 触发器
    7. 设置触发时间,按红框步骤即可,至此“思源自动签到”部署基本完成
  2. 代码如下:

def handler(event, context):

    import requests
    import re
    import hashlib

 

    paras = {
        "username": "填写你的用户名",
        "password": "填写你的密码",
    }

 

    headers = {
        'authority': 'ld246.com',
        'accept': '*/*',
        'accept-language': 'zh-CN,zh;q=0.9',
        'cache-control': 'no-cache',
        'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'origin': 'https://ld246.com',
        'pragma': 'no-cache',
        'referer': 'https://ld246.com/login?goto=https://ld246.com/settings/point',
        'sec-ch-ua': '^\\^Not_A',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '^\\^Windows^\\^',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'same-origin',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.70',
        'x-requested-with': 'XMLHttpRequest',
    }

 

    headersCheckIn = {
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
        'Accept-Language': 'zh-CN,zh;q=0.9',
        'Cache-Control': 'no-cache',
        'Connection': 'keep-alive',
        'Pragma': 'no-cache',
        'Referer': 'https://ld246.com/settings/point',
        'Sec-Fetch-Dest': 'document',
        'Sec-Fetch-Mode': 'navigate',
        'Sec-Fetch-Site': 'same-origin',
        'Sec-Fetch-User': '?1',
        'Upgrade-Insecure-Requests': '1',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.70',
        'sec-ch-ua': '^\\^Not_A',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '^\\^Windows^\\^',
    }

 

    headersDayliCheck = {
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
        'Accept-Language': 'zh-CN,zh;q=0.9',
        'Cache-Control': 'no-cache',
        'Connection': 'keep-alive',
        'Pragma': 'no-cache',
        'Referer': 'https://ld246.com/activity/checkin',
        'Sec-Fetch-Dest': 'document',
        'Sec-Fetch-Mode': 'navigate',
        'Sec-Fetch-Site': 'same-origin',
        'Sec-Fetch-User': '?1',
        'Upgrade-Insecure-Requests': '1',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.70',
        'sec-ch-ua': '^\\^Not_A',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '^\\^Windows^\\^',
    }

 

    log = ""

 

    def appendLog(tempLog):
        nonlocal log
        log = log + tempLog + "\n"

 

    def printLog():
        nonlocal log
        print(log)

 

    def getMsg(htmltext):
        try:
            scoreGet = re.search("(今日签到获得.*积分)", htmltext).group(1)
            scoreGet = re.sub("<[^<]*>", "", scoreGet)
            scoreTotal = re.search("(积分余额[\s0-9]*)", htmltext).group(1)
            appendLog(scoreGet + "\n" + scoreTotal)
            getTopic()
        except:
            print("获取排行信息失败")

 

    def getTopic():
        resp = session.get("https://ld246.com/top/checkin/today", data=data, headers=headersDayliCheck,
                           verify=False, proxies=proxy)
        index = re.search("([0-9]+)\.\s+<a[^<]+aria-name=\"" + paras["username"], resp.text, re.S).group(1)
        count = len(re.findall("([0-9]+)\.\s+<a[^<]+aria-name=\"", resp.text, re.S))
        appendLog("今日奖励排行第" + index + ",超过了" + str((1 - int(index) / count) * 100) + "%的人")

 

    proxy = None

 

    md5 = hashlib.md5(paras["password"].encode(encoding='utf-8')).hexdigest()
    data = '{"nameOrEmail":"' + paras["username"] + '","userPassword":"' + md5 + '","captcha":""}'
    session = requests.session()
    response = session.post('https://ld246.com/login?goto=https://ld246.com/settings/point', data=data, headers=headers,
                            verify=False, proxies=proxy)
    print("登录结果" + response.text)
    tokenName = response.json()["tokenName"]
    token = response.json()["token"]

 

    cookie = {tokenName: token}

 

    response = session.get("https://ld246.com/activity/checkin", cookies=cookie, proxies=proxy, headers=headersCheckIn,
                           verify=False)

 

    if response.text.find("领取今日签到奖励") >= 0:
        res = re.findall(r"<a href=\"([^>^\"]*)\"[^>]*>领取今日签到奖励</a>", response.text, re.S)
        if len(res) > 0:
            appendLog("开始签到")
            response = session.get(res[0], proxies=proxy, headers=headersDayliCheck, verify=False)
            if response.text.find("今日签到获得") >= 0:
                appendLog("签到成功")
                getMsg(response.text)
        else:
            appendLog("未找到签到链接")
    elif response.text.find("今日签到获得") >= 0:
        appendLog("已经签到过了")
        getMsg(response.text)
    else:
        appendLog("签到异常")
    printLog()

 

Fang-L 最后更新于 2024/4/24

回复内容
zn442001 2024-06-24 07:29
#1

谢谢  设置 了

回复主贴