【发布时间】:2017-06-14 23:58:23
【问题描述】:
我正在尝试让 beautifulsoup 使用 URL,如下所示:
from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen("http://proxies.org")
soup = BeautifulSoup(html.encode("utf-8"), "html.parser")
print(soup.find_all('a'))
但是,我收到一个错误:
File "c:\Python3\ProxyList.py", line 3, in <module>
html = urlopen("http://proxies.org").encode("utf-8")
AttributeError: 'HTTPResponse' object has no attribute 'encode'
知道为什么吗?可能与 urlopen 函数有关吗?为什么需要 utf-8?
显然,Python 3 和 BeautifulSoup4 似乎存在一些差异,关于给出的示例(现在似乎已经过时或错误)......
【问题讨论】:
-
这最终成为所需的解决方案 - stackoverflow.com/questions/32382686/…
标签: python python-3.x beautifulsoup urlopen