Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
when I am executing the code , i think that the code has mistake but when I I am executing any code the terminal was like this
example 01:
import requests
from bs4 import BeautifulSoup
url = "https://quotes.toscrape.com/"
response = requests.get(url)
if response.status_code == 200:
    soup = BeautifulSoup(response.text , 'html.parser')
    authors_names = soup.find_all('span',class_= 'authors')
    for author_name in authors_names:
       print(author_name.get_text())
else:
    print(f'failed to retrieve the page.status_code:{response.status_code}')


EXAMPLE 02:
a = 5
print(a)

terminal:
File "<stdin>", line 1
    & "C:/Program Files/Python312/python.exe" "c:/Users/Dell/python.py/web scraping.py/test 11.py"


What I have tried:

I HAVE UNINSTALL THE VS CODE AND INSTALL BUT I AM FACING SAME ISSUE IN THE TERMINALS
Posted
Comments
Richard Deeming 4-Jan-24 9:35am    
Why would you think that reinstalling your IDE would magically make invalid code work?

You need to fix the syntax errors in your code. The error message will tell you what those are. If you want someone to help you, then you need to provide the exact error messages you're getting.

1 solution

If you examine the text returned from that web site you will note two things:
1. There are no items of type "span" with the class "authors".
2. There are items of type "small" with the class "author".
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900