版權聲明:本文為CSDN博主「black manba」的原創(chuàng)文章,遵循CC 4.0 BY-SA版權協(xié)議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/weixin_42156283/article/details/110124554
————————————————
1. 網(wǎng)址:http://match.yuanrenxue.com/match/16

2.抓包分析
1.加密參數(shù)分析
進行翻頁請求抓包,發(fā)現(xiàn)加密參數(shù)為m

打上xhr斷點

調試堆棧,發(fā)現(xiàn)m加密代碼位置在9431行 r.m = n[e(528)](btoa, p_s),p_s為時間戳,n[e(528)]鼠標選中放在上面顯示為一個函數(shù),m是通過n[e(528)]這個函數(shù)傳入btoa和時間戳加密生成的,到此分析完畢

2.利用selenium執(zhí)行javascript,并用flask做服務端接口
先執(zhí)行下面代碼,打開猿人學第16題界面
# -*- coding:utf-8 -*-
from selenium import webdriver
from flask import Flask, request
options = webdriver.ChromeOptions()
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
driver = webdriver.Chrome(options=options, executable_path='chromedriver')
driver.maximize_window()
url = 'http://match.yuanrenxue.com/match/16'
driver.get(url)
app = Flask(__name__)
app.debug = False
def get_encrypt_data(timestamp):
js = """return get_m(btoa, "{}");""".format(timestamp)
decrypt_data = driver.execute_script(js)
return decrypt_data
@app.route('/get_m', methods=['GET'])
def douban():
timestamp = request.args.get("timestamp")
m = get_encrypt_data(timestamp)
return m
if __name__ == '__main__':
app.run()
然后打開控制臺,打下斷點,如上面第一步驟中所示位置,后在控制臺輸入get_m = n[e(528)],使n[e(528)]賦值給get_m這個函數(shù),然后過掉斷點,關閉控制臺即可?,F(xiàn)在selenium就能夠執(zhí)行get_m這個函數(shù)了,

3.發(fā)送請求,獲取結果
# -*- coding:utf-8 -*-
import requests
import time
def get_m(timestamp):
url = 'http://127.0.0.1:5000/get_m?timestamp={}'.format(timestamp)
resp = requests.get(url=url)
m = resp.text
return m
headers = {"User-Agent": "yuanrenxue.project"}
sums = 0
for i in range(1, 6):
timestamp = str(int(time.time() * 1000))
m = get_m(timestamp)
url = f"http://match.yuanrenxue.com/api/match/16?page={i}&m={m}&t={timestamp}"
response = requests.get(url=url, headers=headers).json()
for data_dict in response["data"]:
sums += data_dict["value"]
print(sums)