Creating a program to get important news on a site

2
from bs4 import BeautifulSoup
import requests

url = 'http://g1.com.br/'
header = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
                        'AppleWebKit/537.36 (KHTML, like Gecko) '
                        'Chrome/51.0.2704.103 Safari/537.36'}



req = requests.get(url,headers= header)

html = req.text

soup = BeautifulSoup(html,'html.parser')

colecao = soup.find_all(class_="feed-post-body-title gui-text-title gui-color-primary") #div eh texto


for item in colecao:
    print(item.get_text())

The above code should get the top news on the link site. that is with the tag:

<p class="feed-post-body-title gui-text-title gui-color-primary gui-color-hover">

Unfortunately, it is doing nothing and does not return an error ("Process finished with exit code 0"). can anybody help me? I tested with python 2.7

    
asked by anonymous 02.08.2016 / 03:28

1 answer

5

Your class is not complete:

feed-post-body-title gui-text-title gui-color-primary

Should be:

feed-post-body-title gui-text-title gui-color-primary gui-color-hover

In BeautifulSoup whenever you try to find items through an attribute never forget to put the full value of the attribute.

Successfully tested in python 2.7 and python 3.5.

    
02.08.2016 / 11:10