尝试使用BeautifulSoup时出错

时间:2017-12-15 21:33:36

标签: python beautifulsoup python-3.6

对于学校作业,我们需要使用一些moviedata。而不是复制/粘贴我需要的所有信息,我想我会把它从IMDB中删除。但是我不熟悉Python,我在这里遇到了一个问题。

这是我的代码:

import urllib
import urllib.request
from bs4 import BeautifulSoup
url = "http://www.imdb.com"
values = {'q' : 'The Matrix'}
data = urllib.parse.urlencode(values).encode("utf-8")
req = urllib.request.Request(url, data)
response = urllib.request.urlopen(req)
r = response.read()
soup = BeautifulSoup(r)

该代码一直给我错误:

> Traceback (most recent call last):   File "<pyshell#16>", line 1, in
> <module>
>     soup = BeautifulSoup(r)   File "C:\Users\My Name\AppData\Local\Programs\Python\Python36-32\lib\site-packages\bs4\__init__.py",
> line 153, in __init__
>     builder = builder_class()   File "C:\Users\My Name\AppData\Local\Programs\Python\Python36-32\lib\site-packages\bs4\builder\_htmlparser.py",
> line 39, in __init__
>     return super(HTMLParserTreeBuilder, self).__init__(*args, **kwargs) TypeError: __init__() got an unexpected keyword argument 'strict

&#39;

你们中的任何一个人都知道我做错了吗?

我尝试使用谷歌并发现一篇帖子提到它与请求有关,所以我对请求进行了解除请求并再次安装...没有用。

0 个答案:

没有答案