国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

python - BeautifulSoup指定lxml作為解析器報(bào)錯(cuò)?

瀏覽:119日期:2022-09-01 08:34:14

問題描述

環(huán)境:windows 10PyCharm 2016.3.2

遇到問題:

剛開始學(xué)python,想用BeautifulSoup解析網(wǎng)頁,但出現(xiàn)報(bào)錯(cuò):

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)了這樣的報(bào)錯(cuò):

python - BeautifulSoup指定lxml作為解析器報(bào)錯(cuò)?

在Google搜了下,都是說要導(dǎo)入路徑,但是在 Settings -> Project -> Project Interpreter 里是這樣的

python - BeautifulSoup指定lxml作為解析器報(bào)錯(cuò)?

顯示BeautifulSoup已經(jīng)導(dǎo)入了

請問我要怎么做才能解決這個(gè)問題呢?

萬分感謝!

問題解答

回答1:

找了其他人的代碼看,終于知道是什么問題

并不是路徑的問題,而是傳參的問題

markup 其實(shí)是要解析的內(nèi)容,例如:

soup = BeautifulSoup('<html>data</html>', 'lxml')

或者

markup = '<html>data</html>'soup = BeautifulSoup(markup, 'lxml')

PS. 在文檔中沒有函數(shù)參數(shù)列表之類的,不知道是不是找的位置錯(cuò)了...

回答2:

pip install lxml

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 夏津县| 尖扎县| 阳朔县| 福建省| 乳山市| 屯昌县| 抚顺市| 大理市| 梁山县| 承德市| 天水市| 安泽县| 宿州市| 定襄县| 社旗县| 房山区| 武鸣县| 永德县| 巫溪县| 竹北市| 金平| 临猗县| 定兴县| 嘉义市| 登封市| 阳信县| 柳江县| 元氏县| 多伦县| 辽源市| 常山县| 名山县| 阿克陶县| 崇阳县| 建始县| 民丰县| 芷江| 灵台县| 黑河市| 东宁县| 喀喇沁旗|