python - BeautifulSoup指定lxml作为解析器报错?
天蓬老师
天蓬老师 2017-04-18 10:25:19
0
2
630

环境:
windows 10
PyCharm 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已经导入了

请问我要怎么做才能解决这个问题呢?

万分感谢!

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

membalas semua(2)
阿神

Saya melihat kod orang lain dan akhirnya mengetahui apa masalahnya

Ini bukan masalah dengan laluan, tetapi masalah dengan lulus parameter

markup sebenarnya ialah kandungan yang hendak dihuraikan, contohnya:

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

atau

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

PS. Tiada senarai parameter fungsi dalam dokumen Saya tidak tahu jika saya mencari di tempat yang salah...

Peter_Zhu
pip install lxml
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!