Skip to content

Commit a418b98

Browse files
committed
BeautifulSoup
1 parent d97dd27 commit a418b98

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

03 - BeautifulSoup/news.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import requests
2+
from bs4 import BeautifulSoup
3+
4+
response = requests.get('https://g1.globo.com/')
5+
6+
content = response.content
7+
8+
site = BeautifulSoup(content, 'html.parser')
9+
10+
# HTML da notícia
11+
noticia = site.find('div', attrs={'class': 'feed-post-body'})
12+
13+
# Título
14+
titulo = noticia.find('a', attrs={'class': 'feed-post-link'})
15+
16+
print(titulo.text)
17+
18+
# Subtítulo: div class="feed-post-body-resumo"
19+
subtitulo = noticia.find('div', attrs={'class': 'feed-post-body-resumo'})
20+
21+
print(subtitulo.text)

0 commit comments

Comments
 (0)