应粉需求,让帮写个简单的新赚吧每日打卡程序,就用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>''', ''' ''')
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("打卡异常")
推送效果如下图: