标签:hex data smart 代码 shared encode 目标 技术分享 pen
import time import random import re import hashlib import requests from scrapy import Selector url = ‘http://fanyi.youdao.com/‘ s = requests.Session() s.headers = { ‘Referer‘: ‘http://fanyi.youdao.com‘, ‘User-Agent‘: ‘Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36‘} # Get cookies r_url = s.get(url) # Get latest D for md5 from file fanyi.min.js # <script type="text/javascript" src="http://shared.ydstatic.com/fanyi/newweb/v1.0.9/scripts/newweb/fanyi.min.js"></script> # sel = Selector(text=r_url.text) # url_js = sel.css(‘script::attr(src)‘).re_first(‘.*fanyi.min.js‘) # r_js = s.get(url_js) # D = re.search(r‘D\s*=\s*"(.*?)"‘, r_js.text).group(1) # print(D) D = ‘ebSeFb%=XZ%T[KZ)c(sy!‘ url_post = ‘http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule‘ data = dict( # i = ‘have you eaten‘, i = ‘你吃饭了吗?‘, # from = ‘AUTO‘, to = ‘AUTO‘, smartresult = ‘dict‘, client = ‘fanyideskweb‘, doctype = ‘json‘, version = ‘2.1‘, keyfrom = ‘fanyi.web‘, action = ‘FY_BY_CLICKBUTTION‘, typoResult = ‘false‘ ) salt = str(int(time.time()*1000) + random.randint(0, 9)) print(salt) m = hashlib.md5() m.update((data[‘client‘]+data[‘i‘]+salt+D).encode(‘utf-8‘)) sign = m.hexdigest() print(sign) data.update({‘from‘: ‘AUTO‘, ‘salt‘: salt, ‘sign‘: sign}) r_post = s.post(url_post, data=data) print(r_post.json())
标签:hex data smart 代码 shared encode 目标 技术分享 pen
原文地址:https://www.cnblogs.com/my8100/p/js_youdaofanyi.html