0

我在使用 Beautiful Soup 的 Google 应用引擎中创建了一个应用程序。我正在使用它的最新版本,http://www.crummy.com/software/BeautifulSoup/bs4/download/4.0/。一切正常,直到我将其上传到 GAE。然后发生的事情是我收到了这个错误:

Traceback (most recent call last):
  File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp25.py", line 701, in __call__
    handler.get(*groups)
  File "/base/data/home/apps/s~app/1.358226218191077920/main.py", line 285, in get
    self.response.out.write(self.makeQuery("9147094591"))
  File "/base/data/home/apps/s~app/1.358226218191077920/main.py", line 191, in makeQuery
    from bs4 import BeautifulSoup
  File "/base/data/home/apps/s~app/1.358226218191077920/bs4/__init__.py", line 29, in <module>
    from .builder import builder_registry
  File "/base/data/home/apps/s~app/1.358226218191077920/bs4/builder/__init__.py", line 279, in <module>
    from . import _htmlparser
  File "/base/data/home/apps/s~app/1.358226218191077920/bs4/builder/_htmlparser.py", line 23, in <module>
    from bs4.element import (
  File "/base/data/home/apps/s~app/1.358226218191077920/bs4/element.py", line 6, in <module>
    from bs4.dammit import EntitySubstitution
  File "/base/data/home/apps/s~app/1.358226218191077920/bs4/dammit.py", line 254
    smart_quotes_re = b"([\x80-\x9f])"
                                     ^
SyntaxError: invalid syntax

当我查看 dammit.py 中的第 254 行时,我发现:

if (self.smart_quotes_to is not None
    and proposed.lower() in self.ENCODINGS_WITH_SMART_QUOTES):
    smart_quotes_re = b"([\x80-\x9f])"
    smart_quotes_compiled = re.compile(smart_quotes_re)
    markup = smart_quotes_compiled.sub(self._sub_ms_char, markup)

我真的看不出有什么问题。我尝试过其他版本的 BS,但它们不起作用,因为我使用的是 soup.select("CSS SELECTOR"),它似乎只能在最新版本中使用。

但是,正如我之前所说,它在我的计算机上运行良好,但在云中却不行。

4

1 回答 1

2

BeautifulSoup 4 需要 Python 2.7 或更高版本,但 Appengine 默认使用 Python 2.5。您可以:

于 2012-04-15T13:57:57.887 回答