前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >新赚吧每日打卡-Python源码

新赚吧每日打卡-Python源码

作者头像
偶尔敲代码
发布2023-04-28 10:20:10
4260
发布2023-04-28 10:20:10
举报
文章被收录于专栏:偶尔敲代码

应粉需求,让帮写个简单的新赚吧每日打卡程序,就用Python写个简单易懂的,一行一行往下看应该就看得懂,也就70行,核心的就2行。

主要用到requests和urllib库,urllib只是发通知中文转码用的。

以下代码中域名的地方用*****代替了,自行替换。

代码语言:javascript
复制
import requests
from urllib import parse

cookies = '''【改成你的cookies,包含大括号】'''#浏览器上登录后按F12,切换到网络(Network)——标头
p_token= ''#push+token,需要推送填写,不需要不填

headers = {
        "Connection": "keep-alive",
        "sec-ch-ua": '''"Chromium";v="21", " Not;A Brand";v="99"''',
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": "Windows",
        "Upgrade-Insecure-Requests": "1",
        "DNT": "1",
        "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36",
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
        "Sec-Fetch-Site": "same-origin",
        "Sec-Fetch-Mode": "navigate",
        "Sec-Fetch-User": "?1",
        "Sec-Fetch-Dest": "document",
        #域名自己添加
        "Referer": "https://v1.*****.net/thread-105116-1-1.html?comefrom=6",
        "Accept-Encoding": "gzip, deflate, br",
        "Accept-Language": "zh-CN,zh;q=0.9,yo;q=0.8",
        "Cookie": cookies}

def 取中间文本(html, start_str, end):
    start = html.find(start_str)
    if start >= 0:
        start += len(start_str)
        end = html.find(end, start)
        if end >= 0:
            return html[start:end].strip()

def 取果果():#域名自己添加
    url = "https://v1.*****.net/home.php?mod=spacecp&ac=credit&showcredit=1"
    response = requests.get(url=url, headers=headers)
    #print(response.text)
    try:
        if response.text.find("果果") != -1:
            guo = 取中间文本(response.text, '''果果: </em>''', '''  &nbsp;''')
            dong = 取中间文本(response.text, '''果冻: </em>''', ''' </li>''')
            jf = 取中间文本(response.text, '''<em>积分: </em>''', ''' <span class=''')
            b = f"总积分:{jf},果果:{guo},果冻:{dong}"
        else:
            b = "积分获取失败"
    except Exception:
        b = "积分获取失败"
    return b

#以下是程序开始运行的地方,上面都是调用的子程序和变量
#域名自己添加
url = "https://v1.******.net/plugin.php?id=dsu_paulsign:sign&operation=qiandao&infloat=0&inajax=0"
response = requests.get(url=url,headers=headers)
#print(response.text)
title = parse.quote_plus('xzk8打卡')
try:
    if response.text.find("签到成功") != -1:
        a = 取中间文本(response.text,'''<div class="c">''','''<a href=''')
        g = 取果果()
        print(a + "\n" + g)
        content = parse.quote_plus(a + "\n" + g + "\n微信公众号【偶尔敲代码】")
        requests.get(f'http://www.pushplus.plus/send?token={p_token}&title={title}&content={content}')
    elif response.text.find("已经签到") != -1:
        a = 取中间文本(response.text, '''<div class="c">''', '''<a href=''')
        g = 取果果()
        print(a + "\n" +g)
        content = parse.quote_plus(a + "\n" + g + "\n微信公众号【偶尔敲代码】")
        requests.get(f'http://www.pushplus.plus/send?token={p_token}&title={title}&content={content}')
    else:
        print("签到失败")
except Exception:
    print("打卡异常")

推送效果如下图:

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-12-14,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 偶尔敲代码 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档