Click here to Skip to main content
15,670,482 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()

I get this error:

/Users/luke/PycharmProjects/pythonProject/venv/bin/python /Users/luke/PycharmProjects/pythonProject/
Traceback (most recent call last):
  File "/Users/luke/PycharmProjects/pythonProject/", 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.
Updated 15-Apr-21 23:37pm
Richard MacCutchan 16-Apr-21 9:26am    
Where is the file "home.html" that you are trying to read?

1 solution

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.
- 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.
Share this answer

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