你可以使用requests库来发送HTTP请求并获取网页源码,然后使用json库来解析返回的JSON数据。以下是一个示例代码:

import requests
import json

# 读取cookie
with open('cookie.txt', 'r') as file:
    cookie = file.read().strip()

# 设置请求头部
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36',
    'Cookie': cookie
}

# 发送请求
response = requests.get('https://middle.zcygov.cn/neoericBacklog/message/count?timestamp=1690792416&app=', headers=headers)

# 获取返回的JSON数据
data = response.json()

# 提取未读条数
unread_count = data['result']['unread']

# 输出未读条数
if unread_count != 0:
    print(f"有 {unread_count} 条未读信息")
else:
    print("没有未读信息")

请将上述代码保存为一个Python文件,并确保在同一目录下存在名为cookie.txt的文件,其中包含需要使用的cookie值。运行代码后,会输出未读信息的条数

写一个python代码监控网站的未读信息如果有未读信息就进行推送读取本地的cookietxt文件读入其中的cookie访问httpsmiddlezcygovcnneoericBacklogmessagecounttimestamp=1690792416&app=提取出返回源码successtrueresultunread0read12total12errornull中unread字段如果不为0输出

原文地址: http://www.cveoy.top/t/topic/iv7q 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录