Python Forum

Full Version: Import requests/beautifulsoup problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey everyone,
Since yesterday I've been trying to solve a problem from Practicepython.org (exactly the 17), that needs to import requests and beautifulsoup and installing them with pip.
I dont get exceptions in the code, but i get nothing, I sucefully installed pip, and then requests and bs4, after trying to make it work for a few hours I tried to copy their solution to see if it works as it should, but it doesnt (i think).

This is the image of my IDLE. Today I checked again on pip, updated it, and tried to install again requests and bs4. I don't know what I'm doing wrong.
https://imgur.com/a/b9rbFeR
[attachment=1432]


Thanks to all of you in advance.
Post code in code tag,can not test code if post image.
Looking at this so has site changed the css tag.
import requests
from bs4 import BeautifulSoup

base_url = 'http://www.nytimes.com'
r = requests.get(base_url)
soup = BeautifulSoup(r.content, 'html.parser')
for story_heading in soup.find_all(class_="css-eylb5n e1lsht870"):
    if story_heading.a:
        print(story_heading.a.text.replace("\n", " ").strip())
    else:
        print(story_heading.contents[0].strip())
Output:
Why the Fed Chair Won’t Call Inflation ‘Transitory’ Anymore Parenting Is Hard. Join Us and the Comedian Michelle Buteau to Vent. In Africa, Dealing With Vaccine Challenges and the Omicron Variant .....
Please don't post images. Post your code (with button insert python) and the error message (with button Insert output)


snippsat was faster
I see, now it works right! Thank you very much to you 2, and I'm sorry for the image, this was my very first post, have a nice day!