I get an Import Error in Python Beautiful Soup

I'm studying Python by myself. I don't know the details yet, but I will make a note of the phenomenon that I stumbled upon. By the way, it's ** Python 3.8.5 **

When scraping, I use ** Beautiful Soup **, but I'm addicted to it once.

Code you want to execute

I tried to extract the title tag.

code


# html_parser.py
import requests
from bs4 import BeautifulSoup

#URL you want to get
url = "http://example.com"

#Get HTML by sending HTTP request with url as argument
response = requests.get(url)

#Character code is automatically encoded
response.encoding = response.apparent_encoding

#HTML parsing
bs = BeautifulSoup(response.text, 'html.parser')
title_tag = bs.find('title')

#Output the text part of the extracted tag
print(title_tag.text)

Click here for execution results

I got an Import Error for Beautiful Soup.

result


Traceback (most recent call last):
  File "c:/python/html.py", line 3, in <module>
    from bs4 import BeautifulSoup
  File "C:\Users\*****\AppData\Local\Programs\Python\Python38\lib\site-packages\bs4\__init__.py", line 31, in <module>
    from .builder import builder_registry, ParserRejectedMarkup
  File "C:\Users\*****\AppData\Local\Programs\Python\Python38\lib\site-packages\bs4\builder\__init__.py", line 7, in <module>
    from bs4.element import (
  File "C:\Users\*****\AppData\Local\Programs\Python\Python38\lib\site-packages\bs4\element.py", line 19, in <module>
    from bs4.formatter import (
  File "C:\Users\*****\AppData\Local\Programs\Python\Python38\lib\site-packages\bs4\formatter.py", line 1, in <module>
    from bs4.dammit import EntitySubstitution
  File "C:\Users\*****\AppData\Local\Programs\Python\Python38\lib\site-packages\bs4\dammit.py", line 13, in <module>
    from html.entities import codepoint2name
  File "c:\python\html.py", line 3, in <module>
    from bs4 import BeautifulSoup
ImportError: cannot import name 'BeautifulSoup' from partially initialized module 'bs4' (most likely due to a circular import) (C:\Users\*****\AppData\Local\Programs\Python\Python38\lib\site-packages\bs4\__init__.py)

If not told, the following has been done

python


pip install beautifulsoup

Even with pip list beautifulsoup4 4.9.1 Can be confirmed.

Then why ...

This is because the file name was "html.py".

It seems that Python has a package called "html" that has been loaded ...

Recommended Posts

I get an Import Error in Python Beautiful Soup
I get an error with import pandas.
I get an error when I put opencv in pyautoGUI
When you get an error in python scraping (requests)
I got an error in vim and zsh in Python 3.7 series
When I get an error with Pylint in Atom on Windows
When I get an error with PyInstaller
Import Error in Python3: No module named'xxxxx'
When I get a chromedriver error in Selenium
I get an error with all yum commands
My Beautiful Soup (Python)
Get date in Python
I get an error when I put a Python plugin in Visual Studio Code under the pyenv environment
[Python] I want to know the variables in the function when an error occurs!
In the Chainer tutorial, I get an error when importing a package. (mock)
When I name the file flask.py in Flask, I get Import Error: cannot import name'Flask'
I got an error when I put opencv in python3 with Raspberry Pi [Remedy]
I got an error that Python couldn't read settings.ini
I get an error when trying meinheld + WebSocket + mongodb
BigQuery-If you get a Reason: responseTooLarge error in Python
Note that I dealt with HTML in Beautiful Soup
What to do if you get an error when importing matplotlib in Python (Mac)
I want to get an error message in Japanese with django Password Change Form
I get an error when I try to raise Python to 3 series using pyenv on Catalina
Get YouTube Comments in Python
I wrote python in Japanese
Get last month in python
Dynamically import scripts in Python
Get Terminal size in Python
Explicitly get EOF in python
Slice error in python (´ ; ω ; `)
I understand Python in Japanese!
Get Evernote notes in Python
What I learned in Python
Get Japanese synonyms in Python
I tried "How to get a method decorated in Python"
I wrote an empty directory automatic creation script in Python
Scraping Google News search results in Python (2) Use Beautiful Soup
What to do if you get Swagger-codegen in python and Import Error: No module named
Solution if the module is installed in Python but you get an error in Jupyter notebook
Get Leap Motion data in Python.
I get a UnicodeDecodeError in mecab-python3
I get "sanity check" and "No module" errors in import numpy
Try scraping with Python + Beautiful Soup
Resolved an error when putting pygame in python3 on raspberry pi
Working with LibreOffice in Python: import
I get an ImportError on appengine_config.py
I get a KeyError in pyclustering.xmeans
[Python] A memorandum of beautiful soup4
Get the desktop path in Python
I got an AttributeError when mocking the open method in python
Write an HTTP / 2 server in Python
Scraping with Python and Beautiful Soup
I get an error when trying to install maec 4.0.1.0 with pip
Get the script path in Python
Develop an investment algorithm in Python 2
I sent an SMS with Python
Scraping with Beautiful Soup in 10 minutes
I wrote Fizz Buzz in Python
I get an OS Error: [Errno 8] Exec format error when running a Flask application with a python command
Get, post communication memo in Python