Click here to Skip to main content
15,112,866 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I'm currently following a tutorial to learn web scraping with Beautiful Soup and when I run the following:

from bs4 import BeautifulSoup

with open('home.html', 'r') as html_file:
    content = html.file .read()
    print(content)


I get this error:

/Users/luke/PycharmProjects/pythonProject/venv/bin/python /Users/luke/PycharmProjects/pythonProject/main.py
Traceback (most recent call last):
  File "/Users/luke/PycharmProjects/pythonProject/main.py", line 3, in <module>
    with open('home.html', 'r') as html_file:
FileNotFoundError: [Errno 2] No such file or directory: 'home.html'

Process finished with exit code 1


What I have tried:

Not much since I have no idea what I'm doing but I appreciate any help.
Posted
Updated 16-Apr-21 0:37am
Comments
Richard MacCutchan 16-Apr-21 9:26am
   
Where is the file "home.html" that you are trying to read?

1 solution

Quote:
File not found error - beautiful soup. Not sure what I'm doing wrong.

Simple, 'home.html' is not where you think it is, or you code do not execute in directory where you think it is.
Solutions
- make sure file is in correct directory and that code execute in correct directory.
- Include directory of file with filename, like 'mydirectory/home.html'.

Only you can find exact solution.
   

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



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