Advertisement
renix1

news g1

Apr 2nd, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup
  3.  
  4.  
  5. class G1(object):
  6.     def __init__(self):
  7.         self._domain = "https://g1.globo.com/"
  8.         self.soup = None
  9.         self.get_content()
  10.    
  11.     def get_content(self):
  12.         try:
  13.             self.soup = BeautifulSoup(requests.get(self._domain).text, 'lxml')
  14.         except Exception as e:
  15.             print("Exceção levantada {}".format(e))
  16.    
  17.     def get_news(self):
  18.         for news_title in  (news.text for news in self.soup.findAll('a', class_='feed-post-link')):
  19.             print(news_title, end='\n\n')
  20.  
  21.  
  22. globo = G1()
  23. globo.get_news()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement