Created
December 25, 2016 13:07
-
-
Save arjun921/3edffbe0f9b98bd5c6f3df514122e1dd to your computer and use it in GitHub Desktop.
Use the BeautifulSoup and requests Python packages to print out a list of all the article titles on the New York Times homepage.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Use the BeautifulSoup and requests Python packages to print out a list of all the article titles on the New York Times homepage. | |
import requests | |
from bs4 import BeautifulSoup | |
url = 'http://www.nytimes.com' | |
r = requests.get(url) | |
r_html = r.text | |
soup = BeautifulSoup(r_html, "lxml") | |
for titles in soup.find_all(class_="story"): | |
title = titles.a | |
print(title.string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment