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

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

python - BeautifulSoup指定lxml作為解析器報錯?

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

問題描述

環(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)了這樣的報錯:

python - BeautifulSoup指定lxml作為解析器報錯?

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

python - BeautifulSoup指定lxml作為解析器報錯?

顯示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

標簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 镶黄旗| 新和县| 岱山县| 平度市| 开封县| 怀远县| 宣城市| 兴仁县| 长岛县| 福泉市| 新郑市| 三穗县| 长岛县| 临武县| 嫩江县| 于田县| 南充市| 定日县| 赤峰市| 扶风县| 密云县| 讷河市| 淮南市| 民和| 内乡县| 沾益县| 沅陵县| 西丰县| 东台市| 会理县| 紫金县| 富裕县| 阳东县| 牟定县| 勃利县| 鸡东县| 沁水县| 弋阳县| 扶沟县| 林州市| 商水县|