/modules/presseurop/pages.py

https://gitlab.com/phyks/weboob · Python · 71 lines · 45 code · 9 blank · 17 comment · 2 complexity · 1469d435d63d87457a34521877f42ea2 MD5 · raw file

  1. "ArticlePage object for presseurope"
  2. # -*- coding: utf-8 -*-
  3. # Copyright(C) 2012 Florent Fourcot
  4. #
  5. # This file is part of weboob.
  6. #
  7. # weboob is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # weboob is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
  19. from weboob.browser.pages import AbstractPage
  20. from weboob.browser.filters.html import CSS, CleanHTML
  21. class PresseuropPage(AbstractPage):
  22. "PresseuropPage object for presseurop"
  23. _selector = CSS
  24. PARENT = 'genericnewspaper'
  25. PARENT_URL = 'generic_news_page'
  26. def on_loaded(self):
  27. self.main_div = self.doc.getroot()
  28. self.element_title_selector = "title"
  29. self.element_author_selector = "a[rel=author], div.profilecartoontext>p>a"
  30. self.element_body_selector = "div.block, div.panel, div.bodytext"
  31. def get_body(self):
  32. element_body = self.get_element_body()
  33. self.try_drop_tree(element_body, "li.button-social")
  34. self.try_drop_tree(element_body, "div.sharecount")
  35. self.try_drop_tree(element_body, "p.ruledtop")
  36. self.try_drop_tree(element_body, "p.ctafeedback")
  37. self.try_drop_tree(element_body, "aside.articlerelated")
  38. self.try_drop_tree(element_body, "div.sharecount")
  39. self.try_drop_tree(element_body, "iframe")
  40. self.clean_relativ_urls(element_body, "http://presseurop.eu")
  41. return CleanHTML('.')(element_body)
  42. def get_title(self):
  43. title = super(self.__class__, self).get_title()
  44. title = title.split('|')[0]
  45. return title
  46. def get_author(self):
  47. author = super(self.__class__, self).get_author()
  48. try:
  49. source = self.doc.getroot().xpath(
  50. "//span[@class='sourceinfo']/a")[0]
  51. source = source.text
  52. author = author + " | " + source
  53. return author
  54. except:
  55. return author
  56. def get_daily_date(self):
  57. plink = self.doc.getroot().xpath("//p[@class='w200']")
  58. if len(plink) > 0:
  59. link = plink[0].xpath('a')[0]
  60. date = link.attrib['href'].split('/')[3]
  61. return date
  62. return None