學習網絡抓取時,第一步出現問題。
執行示例代碼
- from urllib.request import urlopen
- from bs4 import BeautifulSoup
- html = urlopen("http://www.pythonscraping.com/exercises/exercise1.html")
- bsObj = BeautifulSoup(html, "html.parser")
- print(bsObj.h1)
執行結果
Traceback (most recent call last):
File "D:/install/Python_web Scraping/chapter1/BeautifulSoup.py", line 2, in <module> from bs4 import BeautifulSoup ModuleNotFoundError: No module named 'bs4'
備注:在終端中beautiful soup已經成功安裝,但是在IDLE中依然出現該問題。
解決辦法
1.在PyCharm Python文件選項中選擇設置選項點進去
2.然后選擇Project Interpreter
3.雙擊Pip
4.搜索出bs4,點擊安裝即可,會提示安裝成功的消息