message_chaincatcher.py 1.3 KB

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