标签:lan 规则 webkit add hash type 加密 stat xhr
- 翻译内容为动态加载【我们在输入内容翻译时url不变】
- F12打开开发者工具,点击XHR
- 根据响应内容确定真实的url地址 - 查看请求参数是否有加密字符串
请求接口和请求参数中携带的sign
# General Request URL: http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule Request Method: POST Status Code: 200 OK Remote Address: 103.72.47.249:80 Referrer Policy: no-referrer-when-downgrade # Form Data i: hello from: AUTO to: AUTO smartresult: dict client: fanyideskweb salt: 15638736993851 # 动态参数 sign: e9e209901e904afd37a85aba71245937 # 加密字符串,签名 动态参数 ts: 1563873699385 # 动态参数 bv: 53539dde41bde18f4a71bb075fcf2e66 # 动态参数 doctype: json version: 2.1 keyfrom: fanyi.web action: FY_BY_REALTlME
# 别问我,我怎么知道哪些参数是动态参数,每次请求这些参数都是会变得。。。。 # 一般这种在请求参数中带有签名的网站,我们需要找到它加密签名的加密方式,根据加密规则用python代码模拟生成sign,每次请求带上它即可; # 如果参数中没有动态生成的签名,那么我们在请求浏览器时是拿不到响应数据的;
格式化后的HTML代码
- sign也是通过md5进行加密得 - 加密得值为("fanyideskweb" + e + i + "n%A-rKaT5fb[Gy?;N5@Tj") - e是我们翻译得内容,i是当前时间戳+0-9的一个随机数
- 我们只需把e和i添加进去生成md5即可,他的前后两边的值是写死的,
# -*- coding: utf-8 -*- # @Time : 2019/7/23 19:14 import requests import hashlib import random import time url = "http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule" search = input("请输入您要翻译的内容>>>:") # 浏览器的版本加密 bv = hashlib.md5("5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36".encode("utf-8")).hexdigest() # 53539dde41bde18f4a71bb075fcf2e66 print("bv",bv) # 当前时间戳 ts = str(int(time.time()*1000)) # 1563881548992 1563881645504 print("ts",ts) # 当前时间+0-9随机时间 注意是字符串相加 salt = ts + str(random.randint(0,9)) # 15638815489920 print("salt",salt) # fanyideskweb + 要翻译的内容 + salt + n%A-rKaT5fb[Gy?;N5@Tj sign = hashlib.md5(("fanyideskweb" + search + salt + "n%A-rKaT5fb[Gy?;N5@Tj").encode("utf-8")).hexdigest() # 7a3f1f22b5f1a7f29a0a6f16ec668c57 print("sign",sign) headers = { ‘Accept‘:‘application/json, text/javascript, */*; q=0.01‘, ‘Accept-Encoding‘:‘gzip, deflate‘, ‘Accept-Language‘:‘zh-CN,zh;q=0.9‘, ‘Connection‘:‘keep-alive‘, ‘Content-Length‘:‘260‘, ‘Content-Type‘:‘application/x-www-form-urlencoded; charset=UTF-8‘, ‘Cookie‘:‘OUTFOX_SEARCH_USER_ID=-457558277@10.108.160.18; JSESSIONID=aaaOxgG-XSZxs54rYhEWw; OUTFOX_SEARCH_USER_ID_NCOO=1830264100.2982109; ___rl__test__cookies=1563881941982‘, ‘Host‘:‘fanyi.youdao.com‘, ‘Origin‘:‘http://fanyi.youdao.com‘, ‘Referer‘:‘http://fanyi.youdao.com/‘, ‘User-Agent‘:‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36‘, ‘X-Requested-With‘:‘XMLHttpRequest‘, } data = { ‘i‘: search, ‘from‘:‘AUTO‘, ‘to‘:‘AUTO‘, ‘smartresult‘:‘dict‘, ‘client‘:‘fanyideskweb‘, ‘salt‘: salt, ‘sign‘: sign, ‘ts‘: ts, ‘bv‘: bv, ‘doctype‘:‘json‘, ‘version‘:‘2.1‘, ‘keyfrom‘:‘fanyi.web‘, ‘action‘:‘FY_BY_CLICKBUTTION‘, } response = requests.post(url=url,headers=headers,data=data).text print(response) python代码
标签:lan 规则 webkit add hash type 加密 stat xhr
原文地址:https://www.cnblogs.com/youxiu123/p/11624380.html