Python 不能使用BeautifulSoup
我使用的是Python 3.6,并且已经使用pip安装了beautifulsoup4。但是,如果我在Python3环境中从bs4导入BeautifulSoup输入,我会得到以下跟踪。我已经按照一些类似帖子的建议更新了beautifulsoup和html5,但还没有解决这个问题Python 不能使用BeautifulSoup,python,beautifulsoup,Python,Beautifulsoup,我使用的是Python 3.6,并且已经使用pip安装了beautifulsoup4。但是,如果我在Python3环境中从bs4导入BeautifulSoup输入,我会得到以下跟踪。我已经按照一些类似帖子的建议更新了beautifulsoup和html5,但还没有解决这个问题 {'results': [], 'status': 'ZERO_RESULTS'} AttributeError: module 'copy' has no attribute 'deepcopy' The above
{'results': [], 'status': 'ZERO_RESULTS'}
AttributeError: module 'copy' has no attribute 'deepcopy'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "part.py", line 1, in <module>
from bs4 import BeautifulSoup as bs
File "/anaconda/lib/python3.6/site-packages/bs4/__init__.py", line 35, in <module>
from .builder import builder_registry, ParserRejectedMarkup
File "/anaconda/lib/python3.6/site-packages/bs4/builder/__init__.py", line 323, in <module>
from . import _html5lib
File "/anaconda/lib/python3.6/site-packages/bs4/builder/_html5lib.py", line 20, in <module>
import html5lib
File "/anaconda/lib/python3.6/site-packages/html5lib/__init__.py", line 16, in <module>
from .html5parser import HTMLParser, parse, parseFragment
File "/anaconda/lib/python3.6/site-packages/html5lib/html5parser.py", line 6, in <module>
from . import inputstream
File "/anaconda/lib/python3.6/site-packages/html5lib/inputstream.py", line 10, in <module>
from . import utils
File "/anaconda/lib/python3.6/site-packages/html5lib/utils.py", line 8, in <module>
import xml.etree.cElementTree as default_etree
File "/anaconda/lib/python3.6/xml/etree/cElementTree.py", line 3, in <module>
from xml.etree.ElementTree import *
File "/anaconda/lib/python3.6/xml/etree/ElementTree.py", line 1654, in <module>
from _elementtree import *
SystemError: <built-in function __import__> returned a result with an error set
{'results':[],'status':'ZERO_results'}
AttributeError:模块“copy”没有属性“deepcopy”
上述异常是以下异常的直接原因:
回溯(最近一次呼叫最后一次):
文件“part.py”,第1行,在
从bs4导入BeautifulSoup作为bs
文件“/anaconda/lib/python3.6/site packages/bs4/_init__.py”,第35行,在
从.builder导入builder_注册表,parserretjectedmarkup
文件“/anaconda/lib/python3.6/site packages/bs4/builder/_init__.py”,第323行,在
从…起导入html5lib
文件“/anaconda/lib/python3.6/site packages/bs4/builder/_html5lib.py”,第20行,在
导入html5lib
文件“/anaconda/lib/python3.6/site packages/html5lib/_init__.py”,第16行,在
从.html5parser导入HTMLParser、parse、parseFragment
文件“/anaconda/lib/python3.6/site packages/html5lib/html5parser.py”,第6行,在
从…起导入输入流
文件“/anaconda/lib/python3.6/site packages/html5lib/inputstream.py”,第10行,在
从…起导入UTIL
文件“/anaconda/lib/python3.6/site packages/html5lib/utils.py”,第8行,在
导入xml.etree.cElementTree作为默认的\u etree
文件“/anaconda/lib/python3.6/xml/etree/celementree.py”,第3行,在
从xml.etree.ElementTree导入*
文件“/anaconda/lib/python3.6/xml/etree/ElementTree.py”,第1654行,在
从元素树导入*
SystemError:返回了一个带有错误集的结果
我认为一个定制模块可能是您编写的名为copy.py
的东西在python的导入路径中,因此当bs4
尝试从stdlib
使用copy.deepcopy
时,它找不到它
从口译员处,执行以下操作:
import copy
然后:
copy.__file__.
如果它不是Python的lib文件夹,那就是你的问题 在我看来,这是一个相当标准的导入错误。您的路径(或PYTHONPATH)中是否有隐藏stdlib
copy
模块的东西?^您能详细说明一下吗?我认为python的导入路径中有一个名为copy.py
的自定义模块(可能是您编写的),因此当bs4
尝试使用copy.deepcopy
(来自stdlib)时,它找不到它。请从解释器中执行导入副本
,然后执行复制。如果它不是Python的lib文件夹,那就是你的问题!你完全正确!我自己永远也想不到。问题解决了!非常感谢。