# -*- coding: utf-8 -*- import sys import os from playwright.sync_api import sync_playwright from bs4 import BeautifulSoup import time from datetime import datetime sys.path.append(os.path.join(os.path.abspath(__file__).split('auto')[0] + 'auto')) from utils.utils_send_gotify import * def chaincatcher_news(): url = "https://www.chaincatcher.com/news" with sync_playwright() as p: browser = p.chromium.launch(headless=True) page = browser.new_page() page.goto(url) time.sleep(2) start_time = time.time() while time.time() - start_time < 10: page.mouse.wheel(0, 100) time.sleep(0.1) page_content = page.content() browser.close() soup = BeautifulSoup(page_content, 'html.parser') contents = [span.get_text(strip=True) for span in soup.find_all('span', class_='text', attrs={'data-v-aea07cf0': True}) if "微信扫码" not in span] result = '\n'.join(contents) result += f'\n推送时间: {datetime.now().strftime("%Y年%m月%d日 %H时%M分%S秒")}' if result: gotify_notifier = GotifyNotifier(title='ChainCatcher News', message=result, token_name='news') gotify_notifier.send_message() print(result) else: print("No news found.") chaincatcher_news()