1
I’m trying to write a code that takes titles from the G1 news and prints them on the screen. The problem is that G1 uses unfinished text(...), ex:
<a class=(...) title="Marcelo Bretas acolhe pedido de transferência de Sérgio Cabral para presídio federal" href=(...)">Marcelo Bretas acolhe pedido de transferência de Sérgio Cabral...</a>
However the attribute "title" contains them complete. How to use Beautifulsoup to take the value of the "title" attribute and print it on the screen ?
What I have so far
import bs4, requests
link = 'http://g1.globo.com/busca/?q='
termo = 'sergio cabral' #Exemplo
completo = link + termo
pegar = requests.get(completo)
pegar.raise_for_status()
soup = bs4.BeautifulSoup(pegar.text, 'html5lib')
selec = soup.select(¯\_(ツ)_/¯)
This answers your question? How to extract text from a selected Beautifulsoap element?
– Lucas