Skip to content

Instantly share code, notes, and snippets.

@arjun921
Created December 25, 2016 13:07
Show Gist options
  • Save arjun921/3edffbe0f9b98bd5c6f3df514122e1dd to your computer and use it in GitHub Desktop.
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.
#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