将站点与tex链接

2024-10-03 17:25:52 发布

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

我想链接一个网站的文字,不知道是什么问题。这是一个节目,本站考察了文中的感受:

import json
from urllib.request import urlopen
from urllib import parse



text= ("i hate you ")
i=parse.quote(text)
API_Call=urlopen( 'http://www.sentiment140.com/api/classify?text= '+ i )
f=json.loads(API_Call.read())
print (f)

Tags: textfromimportapijsonparse网站链接
1条回答
网友
1楼 · 发布于 2024-10-03 17:25:52

我运行了您的代码,发现您面临的问题是urlopen方法给了您一个错误的请求异常。这是因为url中有一个未转义的空间。删除空格,您将得到预期的输出

API_Call=urlopen( 'http://www.sentiment140.com/api/classify?text= '+ i )更改为API_Call=urlopen( 'http://www.sentiment140.com/api/classify?text='+ i )(删除text=之后的空格)以获得预期的输出

附言:下次当你发布问题的时候,包括完整的堆栈跟踪,以便其他人找出问题所在

相关问题 更多 >