简体   繁体   中英

unable to import BeautifulSoup (python 3.6 and bs4-4.1.0)

I have installed bs4 on my system successfully (using python setup.py install). Now the problem is while importing BeautifulSoup in python I'm getting below errors:

C:\Users\dipankar>python
Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from bs4 import BeautifulSoup
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
File "C:\Users\dipankar\AppData\Local\Programs\Python\Python36\lib\site-packages\bs4\__init__.py", line 29, in <module>
from .builder import builder_registry
File "C:\Users\dipankar\AppData\Local\Programs\Python\Python36\lib\site-packages\bs4\builder\__init__.py", line 294, in <module>
 from . import _htmlparser
  File "C:\Users\dipankar\AppData\Local\Programs\Python\Python36\lib\site-    packages\bs4\builder\_htmlparser.py", line 7, in <module>
from html.parser import (
ImportError: cannot import name 'HTMLParseError'
>>>

After doing a lot of google searches

pip install --upgrade beautifulsoup4

worked for me.

As you can read here

because HTMLParseError is deprecated from Python 3.3 onwards and removed in Python 3.5.

I will recommend you to use other parser. Check BeautifulSoup Documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM