Skip to content Skip to sidebar Skip to footer

Decode A Web Page Using Request And Beautifulsoup Package

I am trying a practice question of python. The question is 'Use the BeautifulSoup and requests Python packages to print out a list of all the article titles on the New York Times h

Solution 1:

Where did you get that class tag ? This is not the right one.

You need to replace css-1vctqli esl82me2 by css-1j836f9 esl82me3

import requests
from bs4 import BeautifulSoup
from urllib.request import urlopen

base_url = 'https://www.nytimes.com/'
r = requests.get(base_url)
soup = BeautifulSoup(urlopen(base_url))

get_titles = soup.find_all(class_ = "css-1j836f9 esl82me3")

print()
for title in get_titles:
    print(title.text)

And the output :

enter image description here

Post a Comment for "Decode A Web Page Using Request And Beautifulsoup Package"