在MacOS上,我安装了自制软件,然后安装了pip。
尝试使用使用" BeautifulSoup"的Python刮刀。包。
Ran:pip install -r requirements.txt
requirements.txt包括:
BeautifulSoup
ipython
BeautifulSoup给出了一个错误,谷歌搜索后我意识到有一个新版本。所以我跑了:
pip install beautifulsoup4
似乎已正确安装。然后我运行了抓取脚本,我收到以下错误:
Traceback (most recent call last):
File "scrape.py", line 3, in <module>
from BeautifulSoup import BeautifulSoup
ImportError: No module named BeautifulSoup
我尝试在脚本中将BeautifulSoup更改为BeautifulSoup4,但这是同样的错误。
我还能尝试其他什么吗?
答案 0 :(得分:0)
这主要是因为beautifulsoup4
具有不同的接口
以前的版本。
旧版本公开名为BeautifulSoup
的模块。
from BeautifulSoup import BeautifulSoup
在Python中导入模块的新方法是。
from bs4 import BeautifulSoup
然而,似乎你正在使用其他人依靠旧的BeautifulSoup编写的刮刀。要解决此问题,您必须安装旧版本。
也许您可以分享完整的requirements.txt
,我们会看到它正在使用的版本。
答案 1 :(得分:0)
有问题的代码是我创建的。抓取工具使用Python 2.7和旧版本的BeautifulSoup。在我的要求中,没有在requirements.txt中提及Python版本和BeautifulSoup版本是一个错误。在将代码大量发布时出现了新手错误。 :)
我已经更新了自述文件,以指定有关受支持的Python版本的信息。