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

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 4987|回复: 37
收起左侧

[Python 转载] 阿里、腾讯云函数/亚马逊Lambda函数签到+qq推送签到结果(可选)

  [复制链接]
mikeee 发表于 2020-8-29 11:54
本帖最后由 mikeee 于 2020-10-19 00:51 编辑

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

import logging

FORMAT = '%(name)s-%(filename)s[ln:%(lineno)d]'
# FORMAT += '%(asctime)s:'
FORMAT += '%(levelname)s:\n\t%(message)s'

logger = logging.getLogger()
logging.basicConfig(format=FORMAT, level=10)

UA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1309.0 Safari/537.17"
HEADERS = {"User-Agent": UA}

# 运行 get-cookies.exe 后将系统剪贴板内容拷到下面的等号后面
ck_dict = {}
# ck_dict = {"KF4": "FQV091", "_uab_collina": "1552...4", "htVD_213 2_atarget": "1", "htVD_2132_auth": "9c74BfB5ixjxX..."}

# 或用其他方法,例如devtools 或 fiddler4 获取52pojie的cookies
if not ck_dict:
    ck_str = ""  # 拷到引号里面
    # ck_str = "_uab...1322"
    HEADERS.update({"Cookie": ck_str.strip()})


# https://cp.xuthus.cc/ 申请key 并设置测试好酷推
xuthuskey = ""
# xuthuskey = "27a...........................7b"


def main():

    cjar = requests.utils.cookiejar_from_dict(ck_dict)

    url = "https://www.52pojie.cn/home.php?mod=task&do=draw&id=2"
    # 不是进行中的任务

    logger.info("main...")

    def fetch(url):
        try:
            # res = pq(httpx.get(url, cookies=ck_dict).text)("#messagetext")("p").text()
            resp = requests.get(url, cookies=cjar, headers=HEADERS)
        except Exception as exc:
            # raise SystemExit(exc)
            logger.error("exc: %s", exc)
            resp = str(exc)
        try:
            text = resp.text  # type: ignore
        except Exception as exc:
            logger.error("exc: %s", exc)
            text = str(exc)
        return text

    text = fetch(url)

    if "wbs.png" not in text:  # try url2
        url2 = "https://www.52pojie.cn/home.php?mod=task&do=apply&id=2"
        text = fetch(url2)

    if "您需要先登录" in text:
        res = "您需要先登录,可能原因:cookies过期或52破解页面改版"
    elif "不是进行中的任务" in text or "您已申请过此任务" in text:
        res = "今天签过了,明天再来吧"
    else:
        res = "".join(re.findall(r"messagetext[\s\S]*?<p>([\s\S]{,105})</p>", text))
    logger.info(res)

    # try the other url if...
    _ = r"""
    url = "https://www.52pojie.cn/home.php?mod=task&do=apply&id=2"
    text = fetch(url)

    if "您需要先登录" in text:
        res = "签到失败"
    # elif "不是进行中的任务" in text:
    elif "您已申请过此任务" in text:
        res = "今天签过了,明天再来吧"
    else:
        res = "".join(re.findall(r"messagetext[\s\S]*?<p>([\s\S]{,105})</p>", text))
    print(res)
    # """

    if not res:
        logger.info("text[:200]: %s", text[:200])
        res = text[:200]

    if xuthuskey.strip():
        _ = xuthuskey.strip()
        requests.get(f"https://push.xuthus.cc/send/{_}?c=func compute: {res}")


def lambda_handler(event, context):  # aws default
    print(event)
    print(context)
    main()


def main_handler(event, context):  # tencent default
    print(event)
    print(context)
    main()


def handler(event, context):  # aliyun default
    print(event)
    print(context)
    main()


if __name__ == "__main__":
    main()

步骤

  • 下载: https://pan.baidu.com/s/1gAxEoaqICwQQ2br7ly0SPQ 提取码: cxx8  解压后运行 get-cookies.bat(拷cookies到系统剪贴板)
  • 将系统剪贴板里的cookies拷到17行里 ck_dict = {} 取代等号后的{}
    • 或用其他方法(devtools 或 Fiddler4)拷出 Cookie 置入第22行的 ck_str = "" 等号后面。
  • (可选)如希望用qq推送签到后的结果,申请酷推的钥匙序列(参看源码第27行的链接)拷到第28行的等号后面
  • 将文件上传到阿里云函数计算或亚马逊lambda函数并设置好触发

也可以传腾讯云,但我没腾讯账户,没测试过。阿里云和腾讯云已含requests库,上传文件或拷到在线编辑器里就能用。亚马逊云需用pip requests -t 目录名的办法再zip aws.zip * -r将上面的python文件(lamnda_function.py)及requests包一起打包上传。签到结果推送qq部分可以改成用server酱推送微信。不清楚cookies的有效时间,如果太短的话,那么这个云函数签到就没有太大意义了,因为老是要手动更新cookies。 (2020-10-18更新:实测cookies是长期有效,至少从8月中到现在还没有失效过。)注册阿里云、亚马逊云、腾讯云是免费的,但使用云函数则需要提供信用卡信息,不过每个月有足够的免费额运行小项目,运行签到这种自然是绰绰有余。

有其他问题的话跟帖,我知道答案就尽量解答。

纯属学习python云函数。版主别罚我。我都是每天来52破解手动签到。如觉得不妥,请删帖。


免费评分

参与人数 7吾爱币 +12 热心值 +7 收起 理由
khzhao + 1 + 1 感谢您的宝贵建议,我们会努力争取做得更好!
sukanka + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
源啊呢哈 + 1 + 1 用心讨论,共获提升!
linguo2625469 + 2 + 1 谢谢@Thanks!
ZAXOVE + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
苏紫方璇 + 5 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
破解小白:) + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

本帖被以下淘专辑推荐:

  • · 雲方|主题: 31, 订阅: 25

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

 楼主| mikeee 发表于 2020-9-1 00:54
本帖最后由 mikeee 于 2020-9-1 00:56 编辑
Healer-zx 发表于 2020-9-1 00:30
对的,用Chrome登录
# -*- coding: utf-8 -*-

'''
copy 52pojie cookies (json format) to system clipboard.
'''

from time import sleep
import json

import browser_cookie3
import pyperclip

def dict_from_cookiejar(cj):
    """Returns a key/value dictionary from a CookieJar.

    :param cj: CookieJar object to extract cookies from.
    :rtype: dict
    """

    cookie_dict = {}

    for cookie in cj:
        cookie_dict[cookie.name] = cookie.value

    return cookie_dict

def main():
    '''copy 52pojie cookies (json format) to system clipboard.'''

    # try chrome first
    cookies_jar = browser_cookie3.chrome(domain_name="www.52pojie.cn")
    # cookies_dict = requests.utils.dict_from_cookiejar(cookies_jar)
    cookies_dict = dict_from_cookiejar(cookies_jar)

    # try firefox if unsuccessful
    if not cookies_dict:
        try:
            cookies_jar = browser_cookie3.firefox(domain_name="www.52pojie.cn")
            # cookies_dict = requests.utils.dict_from_cookiejar(cookies_jar)
            cookies_dict = dict_from_cookiejar(cookies_jar)
        except Exception as exc:
            print(" browser_cookie3.firefox exc: %s" % exc)
            print(" Unable to fetch cookies...")
            return

    if cookies_dict:
        cookies_str = json.dumps(cookies_dict)
        try:
            pyperclip.copy(cookies_str)
            print(f'52pojiec cookies({cookies_str[:120]}...)已拷至系统剪贴板。')
        except Exception as exc:
            print('拷到系统剪贴板出错:%s' % exc)
        return

    print('未能获取 cookies。')
    print('试试先在 Chrome 或 Firefox 浏览器里登录 www.52pojie.cn')
    return

if __name__ == '__main__':
    main()
    sleep(2)

hmm……, 不知道什么原因,Chrome版本够新?

python环境的话,试试源码,需装browser-cookie3pyperclip

pip install browser-cookie3 pyperclip
python get_cookies.py

xlose13720 发表于 2020-8-29 15:41
[Python] 纯文本查看 复制代码
{"errorCode":-1,"errorMessage":"Traceback (most recent call last):\n  File \"/var/runtime/python3/bootstrap.py\", line 133, in init_handler\n    func_handler = get_func_handler(file.rsplit(\".\", 1)[0], func)\n  File \"/var/runtime/python3/bootstrap.py\", line 159, in get_func_handler\n    mod = imp.load_module(mname, *imp.find_module(mname))\n  File \"/var/lang/python3/lib/python3.6/imp.py\", line 234, in load_module\n    return load_source(name, filename, file)\n  File \"/var/lang/python3/lib/python3.6/imp.py\", line 172, in load_source\n    module = _load(spec)\n  File \"&#975;rozen; importlib._bootstrap&gt;\", line 675, in _load\n  File \"&#975;rozen; importlib._bootstrap&gt;\", line 655, in _load_unlocked\n  File \"&#975;rozen; importlib._bootstrap_external&gt;\", line 674, in exec_module\n  File \"&#975;rozen; importlib._bootstrap_external&gt;\", line 781, in get_code\n  File \"&#975;rozen; importlib._bootstrap_external&gt;\", line 741, in source_to_code\n  File \"&#975;rozen; importlib._bootstrap&gt;\", line 205, in _call_with_frames_removed\n  File \"/var/user/index.py\", line 3\n    import logging\n    ^\nIndentationError: unexpected indent"}

这个提示错误
xygd998 发表于 2020-8-29 12:33
梅石楠 发表于 2020-8-29 12:45
感谢楼主的分享
lvcaolhx 发表于 2020-8-29 14:01
高大上的方法,感谢楼主,学习了.
头像被屏蔽
源啊呢哈 发表于 2020-8-29 15:49
提示: 作者被禁止或删除 内容自动屏蔽
 楼主| mikeee 发表于 2020-8-29 15:54
xlose13720 发表于 2020-8-29 15:41
[mw_shl_code=python,true]{"errorCode":-1,"errorMessage":"Traceback (most recent call last):\n  File  ...

"IndentationError: unexpected indent", 貌似缩进不对。你是在哪里运行?本地系统有python环境的话,那个程序在本地也是可以运行的,例如,python lambda_function.py, 也可以在本地用其他工具查错,例如 pyright  lambda_function.py 或 pylint lambda_function.py
头像被屏蔽
源啊呢哈 发表于 2020-8-29 16:02
提示: 作者被禁止或删除 内容自动屏蔽
xlose13720 发表于 2020-8-29 16:06
mikeee 发表于 2020-8-29 15:54
"IndentationError: unexpected indent", 貌似缩进不对。你是在哪里运行?本地系统有python环境的话,那 ...

我是复制来腾讯云的云函数
 楼主| mikeee 发表于 2020-8-29 16:09
本帖最后由 mikeee 于 2020-8-29 16:12 编辑
源啊呢哈 发表于 2020-8-29 16:02
运行 get-cookies.exe一闪而过。剪切板也没有

错误

你开个 cmd 窗运行 get-cookies,看看有没有什么信息可以帮助找到剪贴版没有拷出cookies的原因。

在阿里云运行云函数的话,那个 lambda_handler 要改成 main_handler。或是改云函数设置的缺省index.main_handler为 index.lambda_handler. 目的就是要让云函数运行 index.py 里存在的东西。
您需要登录后才可以回帖 登录 | 注册[Register]

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

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

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

GMT+8, 2024-5-13 02:20

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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