Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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()
@jcurt2833

This comment has been minimized.

Copy link

@jcurt2833 jcurt2833 commented May 9, 2020

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'

@Abdulkadir234

This comment has been minimized.

Copy link

@Abdulkadir234 Abdulkadir234 commented Jan 9, 2021

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