import time
import requests
from bs4 import BeautifulSoup
import re
# 设置请求头
headers = {
'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.7',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Cache-Control': 'no-cache',
'Cookie': '略',
'Pragma': 'no-cache',
'Priority': 'u=0, i',
'Referer': 'https://home.cnblogs.com/',
'Sec-Ch-Ua': '"Google Chrome";v="129", "Not=A?Brand";v="8", "Chromium";v="129"',
'Sec-Ch-Ua-Mobile': '?0',
'Sec-Ch-Ua-Platform': '"macOS"',
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Site': 'same-site',
'Sec-Fetch-User': '?1',
'Upgrade-Insecure-Requests': '1',
'User-Agent': '略'
}
def send_feishu_message(message):
feishu_webhook_url = "https://open.feishu.cn/open-apis/bot/v2/hook/不告诉你"
data = {
"msg_type": "text",
"content": {
"text": str(message)
}
}
response = requests.post(feishu_webhook_url, json=data)
print(response.text)
if response.status_code == 200:
print("消息发送成功")
else:
print(f"消息发送失败: {response.status_code}")
def _aawhile_():
# 请求 URL
url = 'https://home.cnblogs.com/vip'
# 发送 GET 请求
response = requests.get(url, headers=headers)
# 检查请求是否成功
if response.status_code == 200:
# 获取网页内容
page_content = response.text
soup = BeautifulSoup(page_content, 'html.parser')
li_elements = soup.find_all('li', id=True)
# 提取所有会员号
member_ids = []
for li in li_elements:
href = li.find('a')['title']
# print(href)
match = re.search(r'博客园第(\d+)位VIP会员', href)
if match:
member_ids.append(int(match.group(1)))
# 获取最大会员号
max_member_id = max(member_ids)
if max_member_id > 6664:
send_feishu_message(max_member_id)
send_feishu_message(max_member_id)
send_feishu_message(max_member_id)
send_feishu_message(max_member_id)
send_feishu_message(max_member_id)
print(f"tt最大的会员号是:{max_member_id}")
return True
else:
print(f"dd最大的会员号是:{max_member_id}")
else:
print(f"Failed to retrieve the webpage: {response.status_code}")
return False
if __name__ == '__main__':
# print(_aawhile_());
i = 0
while not _aawhile_():
time.sleep(5)
#睡死你得了 辣鸡!
i+= 1
current_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(f"{current_time} - i={i}")
2024-09-24 14:54:38 - i=360
dd最大的会员号是:6664
2024-09-24 14:54:43 - i=361
dd最大的会员号是:6664
2024-09-24 14:54:49 - i=362
{"StatusCode":0,"StatusMessage":"success","code":0,"data":{},"msg":"success"}
消息发送成功
{"StatusCode":0,"StatusMessage":"success","code":0,"data":{},"msg":"success"}
消息发送成功
{"StatusCode":0,"StatusMessage":"success","code":0,"data":{},"msg":"success"}
消息发送成功
{"StatusCode":0,"StatusMessage":"success","code":0,"data":{},"msg":"success"}
消息发送成功
{"StatusCode":0,"StatusMessage":"success","code":0,"data":{},"msg":"success"}
消息发送成功
tt最大的会员号是:6665