message_chaincatcher.py 1.2 KB

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