不能使用requests.get(网址)运行BeautifulSoup

2024-10-01 11:23:11 发布

您现在位置:Python中文网/ 问答频道 /正文

start_url=requests.get('http://www.delicious.com/golisoda')
soup=BeautifulSoup(start_url)

此代码显示以下错误:

^{pr2}$

Tags: 代码comhttpurlgetwww错误requests
3条回答
from BeautifulSoup import BeautifulSoup
import urllib2
data=urllib2.urlopen('http://www.delicious.com/golisoda').read()
soup=BeautifulSoup(data)

你可能需要使用

使用

soup=BeautifulSoup(start_url.read())

或者

^{pr2}$

使用响应的.content

start_url = requests.get('http://www.delicious.com/golisoda')
soup = BeautifulSoup(start_url.content)

或者,您可以使用解码的unicode文本:

^{pr2}$

请参阅文档的Response content section。在

相关问题 更多 >