Python Forum
Import requests/beautifulsoup problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Import requests/beautifulsoup problem
#1
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
   


Thanks to all of you in advance.
Reply
#2
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 .....
Reply
#3
Please don't post images. Post your code (with button insert python) and the error message (with button Insert output)


snippsat was faster
Reply
#4
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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in import module from other folder akbarza 5 1,435 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  [WORKED AROUND] Problem installing elitech-datareader, 'cannot import build_py_2to3' NeilUK 4 1,718 Jul-09-2023, 10:01 AM
Last Post: NeilUK
  Need help with XPath using requests,time,urllib.request and BeautifulSoup spacedog 3 2,862 Apr-24-2021, 02:48 AM
Last Post: bowlofred
  'urllib3' Module not found when import 'requests' spanz 5 10,280 Jan-06-2021, 05:57 PM
Last Post: snippsat
  Problem with Flask Bcrypt import module marcello86 2 5,737 Aug-31-2020, 08:10 PM
Last Post: marcello86
  submodule import problem deanhystad 3 4,719 Mar-01-2020, 01:52 PM
Last Post: deanhystad
  problem with mapnik in anaconda python 2: from _mapnik import * ImportError: DLL load parsley 0 1,907 Dec-11-2019, 07:50 AM
Last Post: parsley
  Problem in DB requests using if()s nikos 4 2,667 Feb-09-2019, 11:52 PM
Last Post: nikos
  File Import Problem St_Patrick 8 4,329 Aug-04-2018, 02:29 PM
Last Post: St_Patrick
  Requests problem ZarKx 3 3,326 May-22-2018, 12:22 PM
Last Post: ZarKx

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020