BeautifulSoup错误Python 3.4.3

时间:2015-09-17 14:37:10

标签: python python-3.x beautifulsoup

Python 3.4.3(64位)Windows 7 我的bs4 /请求运行正常然后我从我的程序bs1.py:

获得了所有这些东西
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Python34\myprograms\bs1.py", line 1, in <module>
    import requests, bs4
  File "C:\Python34\lib\site-packages\requests\__init__.py", line 58, in <module>
    from . import utils
  File "C:\Python34\lib\site-packages\requests\utils.py", line 12, in <module>
    import cgi
  File "C:\Python34\lib\cgi.py", line 42, in <module>
    import html
  File "C:\Python34\myprograms\html.py", line 11, in <module>
    import bs4
  File "C:\Python34\lib\site-packages\bs4\__init__.py", line 29, in <module>
    from .builder import builder_registry
  File "C:\Python34\lib\site-packages\bs4\builder\__init__.py", line 4, in <module>
    from bs4.element import (
  File "C:\Python34\lib\site-packages\bs4\element.py", line 5, in <module>
    from bs4.dammit import EntitySubstitution
  File "C:\Python34\lib\site-packages\bs4\dammit.py", line 11, in <module>
    from html.entities import codepoint2name
ImportError: No module named 'html.entities'; 'html' is not a package

如果我将每个程序行输入Python Shell,它可以正常工作并找到bs4等 我重新加载了Python 3.4并重新安装了BeautifulSoup并请求并从.zip文件重新加载了bs4文件 但没有变化。就像Run从另一个库执行一样。如果我从CMD线运行,我会得到相同的结果。 代码:

import requests, bs4
url="http://www.utexas.edu/world/univ/alpha/"
page = requests.get(url)
page.raise_for_status()
#soup = bs4.BeautifulSoup((page.text), "html.parser")
soup = bs4.BeautifulSoup((page.text),)
print("soup.title ", soup.title)

1 个答案:

答案 0 :(得分:0)

您有一个名为html.py的本地文件,它掩盖了名为html的标准库包。

重命名文件,或完全删除它。如果您无法找到它,请导入它以打印文件名:

import html; print(html.__file__)

一旦完成,html.entities导入将再次成功。