【问题标题】:Errors importing BeautifulSoup4导入 BeautifulSoup4 时出错
【发布时间】:2015-06-13 22:36:07
【问题描述】:

我正在尝试导入 BeautifulSoup4,但遇到了导入问题。

我将 Python 2.7.9 作为 32 位 Windows (MSC v.1500) 运行

我尝试将 BeautifulSoup4 安装为 tarball 并使用 pip。两次尝试都“安装”了 bs4,但 import bs4 会产生:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\ArcGIS10.2\lib\site-packages\bs4\__init__.py", line 29, in <module>
    from .builder import builder_registry
  File "C:\Python27\ArcGIS10.2\lib\site-packages\bs4\builder\__init__.py", line 294, in <module>
    from . import _htmlparser
  File "C:\Python27\ArcGIS10.2\lib\site-packages\bs4\builder\_htmlparser.py", line 7, in <module>
    from HTMLParser import (
  File "C:\Python27\ArcGIS10.2\lib\HTMLParser.py", line 47, in <module>
    """, re.VERBOSE)
  File "C:\Python27\ArcGIS10.2\lib\re.py", line 190, in compile
    return _compile(pattern, flags)
  File "C:\Python27\ArcGIS10.2\lib\re.py", line 242, in _compile
    raise error, v # invalid expression
sre_constants.error: nothing to repeat

我不知道如何解决这个问题。任何帮助将不胜感激。

【问题讨论】:

  • 这是您的正则表达式错误。在这里发布!
  • 你是怎么安装的?喜欢这个pip install beautifulsoup4??
  • @MauroBaraldi 请原谅我的无知,但我不确定您发布我的正则表达式是什么意思。
  • @sailesh 是的,这就是我使用 pip 安装的方式。
  • 你能贴出代码中断的部分吗?

标签: python beautifulsoup


【解决方案1】:

试试:

from bs4 import BeautifulSoup

【讨论】:

  • 你能把脚本中使用 bs4 模块的部分贴出来吗?
  • from bs4 import BeautifulSoup ## 产生错误消息。然后,当我输入soup = BeautifulSoup(html) 时,我收到错误“Beautiful Soup is not defined”
  • 运行此命令并返回输出:pip freeze | grep -i "soup"
  • 我运行 pip freeze | finstr /i “汤”。输出是 BeautifulSoup==3.2.1, beautifulsoup4==4.3.2。我卸载了 BeautifulSoup 3,但这并没有解决问题。
猜你喜欢
  • 2018-03-13
  • 1970-01-01
  • 1970-01-01
  • 2019-02-03
  • 1970-01-01
  • 1970-01-01
  • 2017-05-05
  • 2012-10-28
  • 2016-09-01
相关资源
最近更新 更多