message_chaincatcher.py 1.3 KB

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