python - BeautifulSoup指定lxml作為解析器報錯?
問題描述
環(huán)境:windows 10PyCharm 2016.3.2
遇到問題:
剛開始學python,想用BeautifulSoup解析網(wǎng)頁,但出現(xiàn)報錯:
UserWarning: No parser was explicitly specified, so I’m using the best available HTML parser for this system ('lxml'). This usually isn’t a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.The code that caused this warning is on line 4 of the file C:/Users/excalibur/PycharmProjects/learn/getMyIP.py. To get rid of this warning, change code that looks like this: BeautifulSoup([your markup])to this: BeautifulSoup([your markup], 'lxml') markup_type=markup_type))
然后根據(jù)提示和官網(wǎng)的文檔加上:BeautifulSoup(markup, 'html.parser')
結(jié)果出現(xiàn)了這樣的報錯:
在Google搜了下,都是說要導入路徑,但是在 Settings -> Project -> Project Interpreter 里是這樣的
顯示BeautifulSoup已經(jīng)導入了
請問我要怎么做才能解決這個問題呢?
萬分感謝!
問題解答
回答1:找了其他人的代碼看,終于知道是什么問題
并不是路徑的問題,而是傳參的問題
markup 其實是要解析的內(nèi)容,例如:
soup = BeautifulSoup('<html>data</html>', 'lxml')
或者
markup = '<html>data</html>'soup = BeautifulSoup(markup, 'lxml')
PS. 在文檔中沒有函數(shù)參數(shù)列表之類的,不知道是不是找的位置錯了...
回答2:pip install lxml
相關(guān)文章:
1. 前端 - html5 audio不能播放2. java固定鍵值轉(zhuǎn)換,使用枚舉實現(xiàn)字典?3. vim - win10無法打開markdown編輯器4. mysql - 千萬數(shù)據(jù) 分頁,當偏移量 原來越大時,怎么優(yōu)化速度5. 如何解決tp6在zend中無代碼提示6. javascript - 有沒有類似高鐵管家的時間選擇插件7. 這是什么情況???8. python - flask學習,user_syy添加報role is invalid keyword for User.9. css - BEM 中塊(Block)有木有什么標準 何時決定一個部分提取為塊而不是其父級的元素呢(Element)?~10. javascript - 微信網(wǎng)頁開發(fā)從菜單進入頁面后,按返回鍵沒有關(guān)閉瀏覽器而是刷新當前頁面,求解決?
