如何在 ubuntu 中將 beautifulsoup 安裝到 python 2.7?

如何在 ubuntu 中將 beautifulsoup 安裝到 python 2.7?

我想我缺少我正在編寫的聊天機器人的依賴項。我正在嘗試為 python 2.7 安裝 beautifulsoup4 。

當我嘗試使用有問題的函數時,程式會傳回此錯誤

/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py:794:
InsecureRequestWarning: Unverified HTTPS request is being made. 
Adding certificate verification is strongly advised. See:
https://urllib3.readthedocs.org/en/latest/security.html InsecureRequestWarning)
Unhandled exception in thread started by <function run at 0x7f24085aaaa0>

Traceback (most recent call last):    
  File "core/main.py", line 77, in run    
    out = func(input.inp, **kw)    
  File "plugins/comic.py", line 88, in comic    
    return val['data']['link']    
KeyError: 'link'

經過一番搜尋後,似乎它可能與缺少依賴項有關(在本例中為 beautifulsoup)

答案1

在所有目前支援的 Ubuntu 版本中開啟終端並運行:

sudo apt-get install python-bs4

Beautiful Soup (python-bs4) 是適用於 Python 2.x 的容錯 HTML 解析器。有兩種不同的軟體包:python-bs4(適用於Python 2.x)和python3-bs4(適用於Python 3.x),為了防止您混淆,還有兩種不同的Python 整合開發環境:IDLE 和IDLE 3把他們跑進去。

相關內容