python - BeautifulSoup指定lxml作為解析器報錯?
問題描述
環境:windows 10PyCharm 2016.3.2
遇到問題:
剛開始學python,想用BeautifulSoup解析網頁,但出現報錯:
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))
然后根據提示和官網的文檔加上:BeautifulSoup(markup, 'html.parser')
結果出現了這樣的報錯:
在Google搜了下,都是說要導入路徑,但是在 Settings -> Project -> Project Interpreter 里是這樣的
顯示BeautifulSoup已經導入了
請問我要怎么做才能解決這個問題呢?
萬分感謝!
問題解答
回答1:找了其他人的代碼看,終于知道是什么問題
并不是路徑的問題,而是傳參的問題
markup 其實是要解析的內容,例如:
soup = BeautifulSoup('<html>data</html>', 'lxml')
或者
markup = '<html>data</html>'soup = BeautifulSoup(markup, 'lxml')
PS. 在文檔中沒有函數參數列表之類的,不知道是不是找的位置錯了...
回答2:pip install lxml
相關文章:
1. docker 下面創建的IMAGE 他們的 ID 一樣?這個是怎么回事????2. 在應用配置文件 app.php 中找不到’route_check_cache’配置項3. html按鍵開關如何提交我想需要的值到數據庫4. objective-c - 自定義導航條為類似美團的搜索欄樣式5. ios - vue-cli開發項目webstrom會在stylus樣式報錯,飆紅,請大神幫忙6. html5 - 用Egret寫的小游戲,怎么分享到微信呢?7. css - BEM 中塊(Block)有木有什么標準 何時決定一個部分提取為塊而不是其父級的元素呢(Element)?~8. css3 - 怎么感覺用 rem 開發的不多啊9. css - width設置為100%之后列表無法居中10. python - 在pyqt中做微信的機器人,要在表格中顯示微信好友的名字,卻顯示不出來,怎么解決?
