Python – Webscraping With BS4

from bs4 import BeautifulSoup
import requests


html_doc = requests.get('https://www.cnnindonesia.com/olahraga')
soup = BeautifulSoup(html_doc.text, 'html.parser')

populer_area =  soup.find(attrs={'class' : 'box feed'})
titles = populer_area.find_all(attrs={'class' : 'box_text'})

for title in titles:
    print(title.find('h2').text)
    print(title.find('span', 'kanal').text)
    print(title.find('span', 'date').text)
    print('-' * 10)

Leave a Reply

Your email address will not be published. Required fields are marked *