|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我用的Python2编的有道词典的翻译的一个程序,但显示了错误,请高人指教
- # coding=utf-8
- import urllib2
- from urlparse import urlparse
- import json
- content = raw_input("请输入需要翻译的内容:")
- url = 'http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule&sessionFrom=dict2.top'
- data = {}
- data['i'] = content
- data['type'] = 'AUTO'
- data['smartresult'] = 'dict'
- data['client'] = 'fanyideskweb'
- data['salt'] = '1500779742675'
- data['sign'] = '0a4aca0a48f2f934c2f2133a05b617dc'
- data['doctype'] = 'json'
- data['version'] = '2.1'
- data['keyfrom'] = 'fanyi.web'
- data['action'] = 'FY_BY_CL1CKBUTTON'
- data['typoResult'] = 'true'
- urlparse(data).encode('utf-8')
- response = urllib2.urlopen(url,data)
- html = response.read().decode('utf-8')
- target = json.loads(html)
- print("翻译结果:%s" % (target['translateResult'][0][0]['tgt']))
复制代码
Traceback (most recent call last):
File "C:/Users/Dell/Desktop/PYTHON/����/�е��ʵ䷭���ı�.py", line 19, in <module>
urlparse(data).encode('utf-8')
File "C:\Python27\lib\urlparse.py", line 134, in urlparse
tuple = urlsplit(url, scheme, allow_fragments)
File "C:\Python27\lib\urlparse.py", line 167, in urlsplit
cached = _parse_cache.get(key, None)
TypeError: unhashable type: 'dict'
- import urllib.request
- import urllib.parse
- url = 'http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule&sessionFrom=https://www.baidu.com/link'
- data = {}
- data['i'] = 'I love FishC.com'
- data['from'] = 'AUTO'
- data['to'] = 'AUTO'
- data['smartresult'] = 'dict'
- data['client'] = 'fanyideskweb'
- data['salt'] = '1498443416905'
- data['sign'] = '7f1f46783b69d95236192822a11b98e2'
- data['doctype'] = 'json'
- data['version'] = '2.1'
- data['keyfrom'] = 'fanyi.web'
- data['action'] = 'FY_BY_CLICKBUTTON'
- data['typoResult'] = 'TRUE'
- data = urllib.parse.urlencode(data).encode('utf-8')
- response = urllib.request.urlopen(url,data)
- html = response.read().decode('utf-8')
- print(html)
复制代码
|
|