tf1_info.py 947 B

12345678910111213141516171819202122232425262728293031323334353637
  1. from bs4 import BeautifulSoup
  2. from media_observer.article import (
  3. TopArticle,
  4. MainArticle,
  5. FrontPage,
  6. )
  7. class Tf1InfoFrontPage(FrontPage):
  8. @staticmethod
  9. def get_top_articles(soup: BeautifulSoup):
  10. all_articles = soup.select("#AllNews__List__0 .AllNewsItem .LinkArticle")
  11. return [
  12. Tf1InfoFrontPage._get_top_article(a, idx)
  13. for idx, a in enumerate(all_articles)
  14. ]
  15. @staticmethod
  16. def _get_top_article(soup: BeautifulSoup, idx: int):
  17. a = soup.select_unique("a")
  18. return TopArticle.create(
  19. title=a.stripped_text,
  20. url=a["href"],
  21. rank=idx + 1,
  22. )
  23. @staticmethod
  24. def get_main_article(soup):
  25. main = soup.select_first("#headlineid .ArticleCard__Title")
  26. url = main.select_unique("a")
  27. return MainArticle.create(
  28. title=url.stripped_text,
  29. url=url["href"],
  30. )