SuperBoy007
发表于 2017-9-6 20:24:04
也遇到这个问题,谢谢提问,谢谢解惑
linda_000
发表于 2017-9-9 00:18:24
谢谢,居然就是去了_o,{:10_266:}
lynnblog
发表于 2017-9-15 15:26:03
也可以使用金山词霸的翻译页面
import urllib.request
import urllib.parse
import ssl
import json
def fy(post):
data = {
'f':'auto',
't':'auto',
'w':post
}
data = urllib.parse.urlencode(data).encode("utf-8")
url = "http://fy.iciba.com/ajax.php?a=fy"
req = urllib.request.Request(url,data)
req.add_header('User-Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36 LBBROWSER')
res = urllib.request.urlopen(req)
html = res.read().decode("utf-8")
target = json.loads(html)
target = target['content']['word_mean']
return target
# print(target)
t = True
while True:
post = input("你要翻译的数值是:")
target = fy(post)
for i in target:
print(i)
y = input("是否继续【y/n】:")
if(y == "y"):
t = True
else:
break
print("结束")
invation
发表于 2017-9-16 10:34:44
jerryxjr1220 发表于 2017-4-30 16:26
data['salt'] = '1493538230701'这个应该是个时间戳,
data['sign'] = '7b50be5ddda95bce3d4b7b9404647c ...
raise JSONDecodeError("Expecting value", s, err.value) from None
JSONDecodeError: Expecting value
照着您的代码,依然报错,请问您第一种是成功了吗?
skk_4
发表于 2017-9-20 09:53:42
salt 和 sign 每次随机生成的,这个时有道的反爬虫机制,需要知道它加密的机制!
# -*- coding:utf-8 -*-
#---python2.7---
import time
import random
import hashlib
#import requests
import urllib
import urllib2
import json
while 1:
url = 'http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule'
content = raw_input('输入>>>: ')
s = "AUTO",
l = "AUTO"
u = 'fanyideskweb'
c = "rY0D^0\'nM0}g5Mm1z%1G4"
d = content
f = str(int(time.time()*1000)+random.randint(1,10))#时间戳salt
sign = hashlib.md5(u + d + f + c).hexdigest()#md5加密签名sign
#print sign
headers = {
#'Accept':'application/json, text/javascript, */*; q=0.01',
#'Accept-Encoding':'gzip, deflate',
#'Accept-Language':'zh-CN,zh;q=0.8,en;q=0.6',
#'Connection':'keep-alive',
#'Content-Length':'222',
#'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
#'Cookie':'JSESSIONID=aaalHNVSigPD8-hsnhf3v; SESSION_FROM_COOKIE=fanyiweb; OUTFOX_SEARCH_USER_ID=526401539@113.16.65.153; _ntes_nnid=1892114ba72ae7f868a29a4db02914a0,1502250589343; _dict_cpm_show=1502250589350; _dict_cpm_close=1; OUTFOX_SEARCH_USER_ID_NCOO=1688640113.572293; ___rl__test__cookies=1502251640921',
#'Host':'fanyi.youdao.com',
#'Origin':'http://fanyi.youdao.com',
'Referer':'http://fanyi.youdao.com/?keyfrom=dict2.index/',
'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36',
#'X-Requested-With':'XMLHttpRequest',
}
data = {}
data['i']=content
data['from']=s
data['to']=l
data['smartresult']='dict'
data['client']='fanyideskweb'
data['salt']=f
data['sign']=sign
data['doctype']='json'
data['version']='2.1'
data['keyfrom']='fanyi.web'
data['action']='FY_BY_CLlCKBUTTON'
data['typoResult']='true'
#res = requests.post(url, data, headers=headers)
#print data
#print res.text
datas = urllib.urlencode(data)
#print data
rq = urllib2.Request(url, datas, headers)
fd = urllib2.urlopen(rq)
html = fd.read()
#print html
tgt = json.loads(html)
print tgt['translateResult']['tgt']
三少爷的jian
发表于 2017-9-22 15:45:59
1304539791 发表于 2017-7-15 19:26
只要把07.url = 'http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule&sessionFrom=nu ...
大神你是咋知道的牛逼啊老铁
古云居士
发表于 2017-9-26 14:06:10
jerryxjr1220 发表于 2017-4-30 16:26
data['salt'] = '1493538230701'这个应该是个时间戳,
data['sign'] = '7b50be5ddda95bce3d4b7b9404647c ...
用第一种方法试了结果返回的结果是请求不合法{:10_266:}应该又做了处理了
迟钝的蜗牛
发表于 2017-9-28 22:29:26
去掉_o就可以了,大神厉害啊!!!!!!!!!!!!!{:7_113:}
胜妹
发表于 2017-10-6 19:02:05
jerryxjr1220 发表于 2017-4-30 16:26
data['salt'] = '1493538230701'这个应该是个时间戳,
data['sign'] = '7b50be5ddda95bce3d4b7b9404647c ...
对头,就是你给的这个网址,但是我在network里面看到的网址不是这个,是http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule;
你是怎么判断的网址是http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc ??
胜妹
发表于 2017-10-6 19:03:58
jerryxjr1220 发表于 2017-4-30 16:26
data['salt'] = '1493538230701'这个应该是个时间戳,
data['sign'] = '7b50be5ddda95bce3d4b7b9404647c ...
对头,就是你给的这个网址,但是我在network里面看到的网址不是这个,是http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule;
你是怎么判断的网址是http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc ??
黄展盈
发表于 2017-10-9 19:23:35
本帖最后由 黄展盈 于 2017-10-9 19:26 编辑
jerryxjr1220 发表于 2017-4-30 16:26
data['salt'] = '1493538230701'这个应该是个时间戳,
data['sign'] = '7b50be5ddda95bce3d4b7b9404647c ...
用这个代码又显示:
请输入需要翻译的内容(输入"q!"退出程序):love
翻译结果:您的请求来源非法,商业用途使用请关注有道翻译API官方网站“有道智云”: http://ai.youdao.com
这个怎么办{:10_266:}
黄展盈
发表于 2017-10-9 19:30:24
胜妹 发表于 2017-10-6 19:03
对头,就是你给的这个网址,但是我在network里面看到的网址不是这个,是http://fanyi.youdao.com/transla ...
我也想知道{:10_250:}
wind杨
发表于 2017-10-18 22:00:39
新人,个人觉得这样是不是易用性更好呢,嘿嘿
import urllib.parse
import urllib.request
import json
def trans():
content = input("请输入需要翻译的内容:")
url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
data = {}
data['i'] = content
data['from'] = 'AUTO'
data['to'] = 'AUTO'
data['smartresult'] = 'dict'
data['client'] = 'fanyideskweb'
data['salt'] = '1508333076510'
data['sign'] = '1b4945929576aa885ae480f99cc87a3f'
data['doctype'] = 'json'
data['version'] = '2.1'
data['keyfrom'] = 'fanyi.web'
data['action'] = 'FY_BY_CLICKBUTTION'
data['typoResult'] = 'true'
data = urllib.parse.urlencode(data).encode('utf-8')
response = urllib.request.urlopen(url, data)
html = response.read().decode('utf-8')
html = json.loads(html)
target = html['translateResult']['tgt']
print("翻译结果:%s" % target)
trans()
while(1):
value = input("是否需要继续翻译:Y/N ? \n")
if value == 'N':
break
elif value == 'Y':
trans()
else:
print('输入错误')
会走的背包
发表于 2017-10-20 07:57:56
wind杨 发表于 2017-10-18 22:00
新人,个人觉得这样是不是易用性更好呢,嘿嘿
高手啊
NoIsFine
发表于 2017-10-27 17:18:39
黄展盈 发表于 2017-10-9 19:23
用这个代码又显示:
请输入需要翻译的内容(输入"q!"退出程序):love
翻译结果:您的请求来源非法, ...
您好,请问这个问题您现在解决了吗?
xiaolizhaozhao
发表于 2017-11-4 20:52:04
1304539791 发表于 2017-7-15 19:26
只要把07.url = 'http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule&sessionFrom=nu ...
这个才是正解。赞赞
爬呀爬
发表于 2017-11-21 16:15:47
{:5_95:}赞,但是为啥去掉_o就好使?
流逝的时光
发表于 2017-11-25 16:17:50
1304539791 发表于 2017-7-15 19:26
只要把07.url = 'http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule&sessionFrom=nu ...
厉害啊 ,可是是什么原因呢
495382781
发表于 2017-11-29 15:59:35
大神们,非法了怎么解决啊
xiaobinbin
发表于 2017-12-28 22:02:09
1304539791 发表于 2017-7-15 19:26
只要把07.url = 'http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule&sessionFrom=nu ...
试了下,确实是去掉"_o"就好了,感谢