将 BeautifulSoup 导入 Monkeyrunner

Importing BeautifulSoup to Monkeyrunner

有没有办法将 BeautifulSoup(或类似的网络抓取工具)导入 monkeyrunner?

将 BeautifulSoup 导入 Python 程序成功。但是,我在导入到 monkeyrunner

时遇到了 importError
ImportError: No module named bs4

经过一番挖掘,我附加了 BeautifulSoup 路径名

import sys

sys.path.append("path/to/monkeyrunner/directory/the_filename.egg") sys.path.append("path/to/monekeyrunner/directory")

这使 Monkeyrunner 能够正确查看 BeautifulSoup 的目录。但是,在 BeautifulSoup 中抱怨一些事情;见下文:

   from bs4 import BeautifulSoup
SyntaxError: ("no viable alternative at input '' ''", ('C:\Python27\lib\site-
packages\bs4\__init__.py', 186, 56, "                if ((isinstance(markup, b
ytes) and not b' ' in markup)\n"))

同样,导入到 python 没有错误。关于为什么 monkeyrunner 会出现这种情况有什么建议吗?

您可以尝试 AndroidViewClient/culebra,即 100% python。它将为您提供 monkeyrunner 中的几乎所有功能以及更多。

bs4 可以毫无问题地导入到您的脚本中。