Web scraping Python 3.5.4错误UserWarning:未显式指定任何解析器

Web scraping Python 3.5.4错误UserWarning:未显式指定任何解析器,web-scraping,beautifulsoup,python-3.5,Web Scraping,Beautifulsoup,Python 3.5,我尝试使用Beautifulsoup4。成功安装后,总会出现一些错误,我无法为soup=BeautifulSouphtml修复它 当我使用以下代码时: from bs4 import BeautifulSoup soup = BeautifulSoup(html) 它显示了错误: //anaconda/lib/python3.5/site-packages/bs4/__init__.py:166: UserWarning: No parser was explicitly specifie

我尝试使用Beautifulsoup4。成功安装后,总会出现一些错误,我无法为soup=BeautifulSouphtml修复它

当我使用以下代码时:

from bs4 import BeautifulSoup  
soup = BeautifulSoup(html)
它显示了错误:

//anaconda/lib/python3.5/site-packages/bs4/__init__.py:166: 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.

To get rid of this warning, change this:

 BeautifulSoup([your markup])

to this:

  BeautifulSoup([your markup], "lxml")

  markup_type=markup_type))
Traceback (most recent call last):

   File "<ipython-input-13-d4b16f497b1d>", line 1, in <module>
runfile('/Users/beckswu/Desktop/coursera/using python access web data/class 2.py', wdir='/Users/beckswu/Desktop/coursera/using python access web data')

   File "//anaconda/lib/python3.5/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile
execfile(filename, namespace)

   File "//anaconda/lib/python3.5/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 88, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)

   File "/Users/beckswu/Desktop/coursera/using python access web data/class 2.py", line 37, in <module>
soup = BeautifulSoup(html)

   File "//anaconda/lib/python3.5/site-packages/bs4/__init__.py", line 212, in __init__
markup, from_encoding, exclude_encodings=exclude_encodings)):

   File "//anaconda/lib/python3.5/site-packages/bs4/builder/_lxml.py", line 108, in prepare_markup
markup, try_encodings, is_html, exclude_encodings)

TypeError: __init__() takes from 2 to 4 positional arguments but 5 were given
它还显示了错误

    markup_type=markup_type))
                       ^
SyntaxError: invalid syntax

我怎样才能解决这个问题?我感谢任何人的帮助。

您需要传递html的文本文件,而不是html,如下所示

from bs4 import BeautifulSoup
request = requests.get("http://www.flipkart.com/search").text
soup = BeautifulSoup(request)

希望这有帮助:

我相信您的代码中有一个错误:

从bs4导入BeautifulSoup 如果您决定使用html作为解析器 soup=BeautifulSouphtml,features=html.parser 第三个参数是**生成器**,它默认为无,因此您不必添加它。实际上它不是**标记类型** 如果您没有lxml,您可以通过运行以下命令来安装它:

pip install lxml 
然后导入它并使用如下方式:

从bs4导入BeautifulSoup 导入lxml soup=BeautifulSouphtml,lxml BeautifulSoup构造函数的参数为:

markup=、features=None、builder=None、parse\u only=None、from\u encoding=None、exclude\u encodings=None和**kwargs.

你认为markup\u type=markup\u type在做什么?
pip install lxml