猿问

显示 response = rullib.request.urlopen(req) NameError: name 'rullib' is not defined求解

import urllib.request

import urllib.parse

import json


content = input('请输入需要翻译的内容:')

url = "http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=dict2.index"


data = {}

data['type'] = 'AUTO'

data['i'] = content

data['doctype'] = 'json'

data['xmlVetsion'] = '1.6'

data['keyfrom'] = 'fanyi.web'

data['ue'] = 'UTF-8'

data['typoResult'] = 'true'

data = urllib.parse.urlencode(data).encode('utf-8')


req = urllib.request.Request(url, data)

response = rullib.request.urlopen(req)

html = response.read().decode('utf-8')


target = json.loads(html)

target = target['translateResult'][0][0]['tgt']


print(target)


衣旧过不好这一生
浏览 2555回答 1
1回答

清波

倒数第五句里面 urllib.request.urlopen(req) 拼写错误, 写成了 rullib.request.urlopen(req)
随时随地看视频慕课网APP

相关分类

Python
我要回答