爬虫之有道翻译(逆向)

  • 版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kun1280437633/article/details/80637374
# -*- coding: utf-8 -*-

import requests
import hashlib
import time
from pprint import pprint

url = "http://fanyi.youdao.com/translate_o"
params = {
    "smartresult": "dict",
    "smartresult": "rule"
}

salt = str(time.time())

client = "fanyideskweb"
text = input("请输入翻译内容:")
AppKey = "ebSeFb%=XZ%T[KZ)c(sy!"
sign = hashlib.md5((client+text+salt+AppKey).encode('utf-8')).hexdigest()

data = {
    "i": text,
    "from": "AUTO",

    "to": "AUTO",
    "smartresult": "dict",
    "client": client,
    "salt": salt,
    "sign": sign,
    "doctype": "json",
    "version": "2.1",
    "keyfrom": "fanyi.web",
    "action": "FY_BY_CLICKBUTTION",
    "typoResult": "false"

}

headers = {
    "User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
    "Referer":"http://fanyi.youdao.com/?keyfrom=dict2.index",
    "Cookie":"OUTFOX_SEARCH_USER_ID_NCOO=1082072868.6526275; [email protected]; YOUDAO_EAD_UUID=800e3e66-ce9f-442d-adbf-9b3979a21a3e; _ntes_nnid=2fe3d5c70463d0c7d9cb34cd85f28f28,1526368710759; fanyi-ad-id=44881; fanyi-ad-closed=1; [email protected]|1527857737|2|mail163|11&19|shh&1527852495&youdaodict_client#shh&null#10#0#0|&0|youdaodict_client&mail163|[email protected]; JSESSIONID=abclAXKrY2C2GhDODT_ow; DICT_LOGIN=8||1527913051232; DICT_FORCE=true; DICT_UGC=be3af0da19b5c5e6aa4e17bd8d90b28a|; ___rl__test__cookies=1527913197589"
}


response = requests.post(url=url,params=params,data=data,headers=headers)

pprint(response.json())

你可能感兴趣的:(python)