【问题标题】:BeautifulSoup error Python 3.4.3BeautifulSoup 错误 Python 3.4.3
【发布时间】:2015-09-17 14:37:09
【问题描述】:

Python 3.4.3(64 位)Windows 7 我的 bs4/requests 运行良好,然后我从我的程序 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 和 requests 并从 .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)

【问题讨论】:

    标签: python python-3.x beautifulsoup


    【解决方案1】:

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

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

    import html; print(html.__file__)
    

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

    【讨论】:

    • 非常感谢,答案总是显而易见的
    猜你喜欢
    • 1970-01-01
    • 2016-03-12
    • 1970-01-01
    • 2012-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-28
    相关资源
    最近更新 更多