|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
var rp=require("sync-request");
var crypto = require('crypto');
var querystr = require('querystring');
var url="https://ifanyi.iciba.com/index.php?";
var q="cat";
var key="6key_cibaifanyicjbysdlove1"+q;
var rmd5 = crypto.createHash('md5').update(key).digest("hex");
var data={
'from': "en",
'to': 'zh',
'q': q
};
var postdata=querystr.stringify(data);
var contentLen = Buffer.byteLength(postdata, 'utf8');
var headers={
'Content-Length': contentLen,
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36',
};
url+=querystr.stringify({'c': 'trans',
'm': 'fy',
'client': '6',
'auth_user': 'key_ciba',
'sign': rmd5.substring(0,16)});
var resp=rp("post",url,headers=headers,json=data);
console.log(resp.getBody('utf8'));
console.log(headers["Content-Length"]);
console.log(data);
console.log(url);
/*
PS D:\wp> node jinshan.js
{"error_code":10005,"message":"auth failed"}
19
{ from: 'en', to: 'zh', q: 'cat' }
https://ifanyi.iciba.com/index.php?c=trans&m=fy&client=6&auth_user=key_ciba&sign=4eaf39c9397e1ba9
*/
里面各种接口数据 都和抓包里面的一致,但是就是无情的返回 auth failed
以为是算法发生变化了,使用python运行差不多一致的源码 ok 没问题
鉴于这个网站既有post 请求 还有url拼接 我又特意写了个demo 然后再我自己demo上运行上面类似代码 也能拿到数据
const { createInterface } = require("readline")
const axios = require('axios').default
const crypto = require('crypto')
const url = "https://ifanyi.iciba.com/index.php?"
const input = question => {
return new Promise((resolve, reject) => {
const readline = createInterface({
input: process.stdin,
output: process.stdout
})
readline.question(question, input => {
input ? resolve(input) : reject()
readline.close()
})
})
}
const main = async () => {
let q
try {
q = await input(`请输入你要翻译的单词::`)
} catch (err) {
console.log(`无输入,结束程序`)
return
}
const key = "6key_cibaifanyicjbysdlove1" + q
const sign = crypto.createHash('md5').update(key).digest("hex").substring(0, 16)
const data = new URLSearchParams()
data.set('from', "auto")
data.set('to', 'auto')
data.set('q', q)
const headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36'
}
try {
resp = await axios.post(url, data.toString(), {
'headers': headers,
'params': {
'c': 'trans',
'm': 'fy',
'client': 6,
'auth_user': 'key_ciba',
'sign': sign
}
})
console.log(resp.data["content"]["out"])
} catch (err) {
console.log(`请求失败:${err}`)
}
}
main()
结账 老哥
|
|