更新时间:2021-09-16 18:37:07
打开python shell并尝试以下操作:
Open a python shell and try the following:
from bs4 import BeautifulSoup
myHTML = "<html><head></heda><body><strong>Hi</strong></body></html>"
soup = BeautifulSoup(myHTML, "lxml")
这行得通,还是相同的错误?如果有同样的错误,则说明您缺少lxml.安装它:
Does that work, or same error? If same error, you're missing lxml. Install it:
pip install lxml
我正在执行这些步骤,因为您指出该脚本在崩溃前已经工作了一段时间,在这种情况下,您不能缺少解析器吗?
I'm going through the steps because you indicate that the script works for a good while before crashing, in which case, you can't be missing the parser?
由OP添加:
If you are using Python2.7 in Ubuntu/Debian, this worked for me:
$ sudo apt-get build-dep python-lxml
$ sudo pip install lxml
Test it like:
mona@pascal:~/computer_vision/image_retrieval$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml