爬虫-破解有道翻译

#!/usr/bin/python3
# -*- coding: utf-8 -*-

'''
如何 把 js 翻译成 python

'''
import requests
import json
from pprint import pprint
import time
import hashlib

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

client = "fanyideskweb"
salt = str(time.time())
word = input("请输入查询单词:") #"as"
signKey = "ebSeFb%=XZ%T[KZ)c(sy!"


# 进行签名
# md5(client + word + salt + signKey)
sign = hashlib.md5((client + word + salt + signKey).encode('utf-8')).hexdigest()



data = {
    "i":word,
    "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_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36",
    "Cookie":"OUTFOX_SEARCH_USER_ID_NCOO=1082072868.6526275; [email protected]; YOUDAO_EAD_UUID=800e3e66-ce9f-442d-adbf-9b3979a21a3e; _ntes_nnid=2fe3d5c70463d0c7d9cb34cd85f28f28,1526368710759; [email protected]|1527857737|2|mail163|11&19|shh&1527852495&youdaodict_client#shh&null#10#0#0|&0|youdaodict_client&mail163|[email protected]; fanyi-ad-id=46607; fanyi-ad-closed=1; DICT_UGC=be3af0da19b5c5e6aa4e17bd8d90b28a|; JSESSIONID=abcsj4r_MYVu14Os7mHsw; ___rl__test__cookies=1531713222210",
    "Referer":"http://fanyi.youdao.com/?keyfrom=dict2.top"
}

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

result = json.loads(response.content.decode('utf-8'))
pprint(result)

猜你喜欢

转载自blog.csdn.net/qq_41868948/article/details/81088420