Skip to content

Instantly share code, notes, and snippets.

@mprat
Created July 5, 2014 10:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mprat/b042a834835cfb4bbe6c to your computer and use it in GitHub Desktop.
Save mprat/b042a834835cfb4bbe6c to your computer and use it in GitHub Desktop.
Print out a list of all headline titles on the New York Times homepage.
import requests
from bs4 import BeautifulSoup
base_url = 'http://www.nytimes.com'
r = requests.get(base_url)
soup = BeautifulSoup(r.text)
for story_heading in soup.find_all(class_="story-heading"):
if story_heading.a:
print story_heading.a.text.replace("\n", " ").strip()
else:
print story_heading.contents[0].strip()
@AbdulkadirGur
Copy link

error messege
Traceback (most recent call last):
File "C:/Users/JonahC/AppData/Roaming/JetBrains/PyCharmCE2020.1/scratches/scratch.py", line 1, in
import requests
ModuleNotFoundError: No module named 'requests'

if you are using pymchar.clıck the alt enter .Click Alt + enter and it will automatically download the required module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment