简体   繁体   中英

About python3.6 when I import bs4, it doesn't work

I import bs4 as:

from bs4 import BeautifulSoup

but it throws an error like this:

Traceback (most recent call last):
  File "/Users/koudai232/Desktop/test.py", line 4, in <module>
    from bs4 import BeautifulSoup
  File "/usr/local/lib/python3.6/site-packages/bs4/__init__.py", line 30, in <module>
    from .builder import builder_registry, ParserRejectedMarkup
  File "/usr/local/lib/python3.6/site-packages/bs4/builder/__init__.py", line 308, in <module>
    from . import _htmlparser
  File "/usr/local/lib/python3.6/site-packages/bs4/builder/_htmlparser.py", line 7, in <module>
    from html.parser import (
ImportError: cannot import name 'HTMLParseError'
[Finished in 0.1s with exit code 1]
[cmd: ['/usr/local/bin/python3', '-u', '/Users/koudai232/Desktop/test.py']]
[dir: /Users/koudai232/Desktop]
[path: /usr/bin:/bin:/usr/sbin:/sbin]

But it works in python2.7. I update my bs4 as :

pip install --upgrade beautifulsoup4

It doesn't work yet.

How to solve this problem ,thanks~!

You should upgrade your beautifulsoup module to be fine with python 3.6. Starting with 4.4.0, BeautifulSoup is compatible with Python 3.5. and above

pip3 install --upgrade beautifulsoup4

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