不知不觉,上次的代码好像出问题了,参考了网上的思路,抽空更新了一下代码,如下:
代码语言:javascript复制import requests,time,re
from urllib import parse
cookies = '''【改成你的cookies,包含大括号】'''#浏览器上登录后按F12,切换到网络(Network)——标头
p_token= ''#push token,需要推送填写,不需要不填
headers = {
'Host': 'v1.xianbao.net',
'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6 Mobile/15E148 Safari/604.1',
'Origin': 'https://v1.xianbao.net',
'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.xianbao.net/home.php?mod=spacecp&ac=credit&showcredit=1"
response = requests.get(url=url, headers = headers, verify = False)
#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
requests.packages.urllib3.disable_warnings()
url = 'https://v1.xianbao.net/'
response = requests.post(url = url, headers = headers, verify = False)
formhash = str(re.findall('name="formhash" value="(.*?)" />', response.text, re.S)).replace('[', '').replace(''', '').replace(']', '')
#print(formhash)
url = 'https://v1.xianbao.net/app.php?p=sign&action=todaysign'
body = {'formhash': f'{formhash}'}
response = requests.post(url = url, headers = headers, data = "", verify = False)
sign = str(re.findall('<div id="messagetext" class="alert.*">n<p>(.*?)<script type="text/javascript" reload="1">', response.text, re.S))
print(sign)
title = parse.quote_plus('xzk8打卡')
try:
g = 取果果()
print(g)
content = parse.quote_plus(sign "n" g "n微信公众号【偶尔敲代码】")
requests.get(f'http://www.pushplus.plus/send?token={p_token}&title={title}&content={content}')
except Exception:
print("打卡异常")
推送效果如下图: