马上爬
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
|
||||
import requests
|
||||
|
||||
def herder_data():
|
||||
headers = {
|
||||
'Host': 'www.mashangpa.com',
|
||||
'Connection': 'keep-alive',
|
||||
'Pragma': 'no-cache',
|
||||
'Cache-Control': 'no-cache',
|
||||
'sec-ch-ua-platform': '"Windows"',
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36',
|
||||
'sec-ch-ua': '"Google Chrome";v="149", "Chromium";v="149", "Not)A;Brand";v="24"',
|
||||
'sec-ch-ua-mobile': '?0',
|
||||
'Accept': '*/*',
|
||||
'Sec-Fetch-Site': 'same-origin',
|
||||
'Sec-Fetch-Mode': 'cors',
|
||||
'Sec-Fetch-Dest': 'empty',
|
||||
'Referer': 'https://www.mashangpa.com/problem-detail/2/',
|
||||
'Accept-Encoding': 'gzip, deflate, br, zstd',
|
||||
'Accept-Language': 'zh-CN,zh;q=0.9,chr;q=0.8',
|
||||
#'Cookie': 'Hm_lvt_0d2227abf9548feda3b9cb6fddee26c0=1782695747; HMACCOUNT=5B22C2BEF2EF9320; sessionid=371wy9tw0s27h36n477hnp6wi7l0htex; Hm_lpvt_0d2227abf9548feda3b9cb6fddee26c0=1782698307'
|
||||
}
|
||||
return headers
|
||||
|
||||
def main(url,headers):
|
||||
num = 0
|
||||
for i in range(1,21):
|
||||
params = {
|
||||
'page': i
|
||||
}
|
||||
data = requests.get(url=url, headers=headers, params=params).json()
|
||||
print(f'当前是{i}页,数据是{data['current_array']},当前页面结果是:{sum(data['current_array'])}')
|
||||
num += sum(data['current_array'])
|
||||
print(f'全部结果是:{num}')
|
||||
|
||||
if __name__ == '__main__':
|
||||
problem_id = 1
|
||||
url = f'https://www.mashangpa.com/api/problem-detail/{problem_id}/data/'
|
||||
headers = herder_data()
|
||||
headers['cookie'] = 'Hm_lvt_0d2227abf9548feda3b9cb6fddee26c0=1782695747; HMACCOUNT=5B22C2BEF2EF9320; sessionid=371wy9tw0s27h36n477hnp6wi7l0htex; Hm_lpvt_0d2227abf9548feda3b9cb6fddee26c0=1782698307'
|
||||
main(url,headers)
|
||||
@@ -0,0 +1,40 @@
|
||||
import requests
|
||||
|
||||
def herder_data():
|
||||
headers = {
|
||||
'Host': 'www.mashangpa.com',
|
||||
'Connection': 'keep-alive',
|
||||
'Pragma': 'no-cache',
|
||||
'Cache-Control': 'no-cache',
|
||||
'sec-ch-ua-platform': '"Windows"',
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36',
|
||||
'sec-ch-ua': '"Google Chrome";v="149", "Chromium";v="149", "Not)A;Brand";v="24"',
|
||||
'sec-ch-ua-mobile': '?0',
|
||||
'Accept': '*/*',
|
||||
'Sec-Fetch-Site': 'same-origin',
|
||||
'Sec-Fetch-Mode': 'cors',
|
||||
'Sec-Fetch-Dest': 'empty',
|
||||
'Referer': 'https://www.mashangpa.com/problem-detail/2/',
|
||||
'Accept-Encoding': 'gzip, deflate, br, zstd',
|
||||
'Accept-Language': 'zh-CN,zh;q=0.9,chr;q=0.8',
|
||||
#'Cookie': 'Hm_lvt_0d2227abf9548feda3b9cb6fddee26c0=1782695747; HMACCOUNT=5B22C2BEF2EF9320; sessionid=371wy9tw0s27h36n477hnp6wi7l0htex; Hm_lpvt_0d2227abf9548feda3b9cb6fddee26c0=1782698307'
|
||||
}
|
||||
return headers
|
||||
|
||||
def main(url,headers):
|
||||
num = 0
|
||||
for i in range(1,21):
|
||||
params = {
|
||||
'page': i
|
||||
}
|
||||
data = requests.get(url=url, headers=headers, params=params).json()
|
||||
print(f'当前是{i}页,数据是{data['current_array']},当前页面结果是:{sum(data['current_array'])}')
|
||||
num += sum(data['current_array'])
|
||||
print(f'全部结果是:{num}')
|
||||
|
||||
if __name__ == '__main__':
|
||||
problem_id = 2
|
||||
url = f'https://www.mashangpa.com/api/problem-detail/{problem_id}/data/'
|
||||
headers = herder_data()
|
||||
headers['cookie'] = 'Hm_lvt_0d2227abf9548feda3b9cb6fddee26c0=1782695747; HMACCOUNT=5B22C2BEF2EF9320; sessionid=371wy9tw0s27h36n477hnp6wi7l0htex; Hm_lpvt_0d2227abf9548feda3b9cb6fddee26c0=1782698307'
|
||||
main(url,headers)
|
||||
@@ -0,0 +1,41 @@
|
||||
|
||||
import requests
|
||||
|
||||
def herder_data():
|
||||
headers = {
|
||||
'Host': 'www.mashangpa.com',
|
||||
'Connection': 'keep-alive',
|
||||
'Pragma': 'no-cache',
|
||||
'Cache-Control': 'no-cache',
|
||||
'sec-ch-ua-platform': '"Windows"',
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36',
|
||||
'sec-ch-ua': '"Google Chrome";v="149", "Chromium";v="149", "Not)A;Brand";v="24"',
|
||||
'sec-ch-ua-mobile': '?0',
|
||||
'Accept': '*/*',
|
||||
'Sec-Fetch-Site': 'same-origin',
|
||||
'Sec-Fetch-Mode': 'cors',
|
||||
'Sec-Fetch-Dest': 'empty',
|
||||
'Referer': 'https://www.mashangpa.com/problem-detail/2/',
|
||||
'Accept-Encoding': 'gzip, deflate, br, zstd',
|
||||
'Accept-Language': 'zh-CN,zh;q=0.9,chr;q=0.8',
|
||||
#'Cookie': 'Hm_lvt_0d2227abf9548feda3b9cb6fddee26c0=1782695747; HMACCOUNT=5B22C2BEF2EF9320; sessionid=371wy9tw0s27h36n477hnp6wi7l0htex; Hm_lpvt_0d2227abf9548feda3b9cb6fddee26c0=1782698307'
|
||||
}
|
||||
return headers
|
||||
|
||||
def main(url,headers):
|
||||
num = 0
|
||||
for i in range(1,21):
|
||||
params = {
|
||||
'page': i
|
||||
}
|
||||
data = requests.get(url=url, headers=headers, params=params).json()
|
||||
print(f'当前是{i}页,数据是{data['current_array']},当前页面结果是:{sum(data['current_array'])}')
|
||||
num += sum(data['current_array'])
|
||||
print(f'全部结果是:{num}')
|
||||
|
||||
if __name__ == '__main__':
|
||||
problem_id = 3
|
||||
url = f'https://www.mashangpa.com/api/problem-detail/{problem_id}/data/'
|
||||
headers = herder_data()
|
||||
headers['cookie'] = 'Hm_lvt_0d2227abf9548feda3b9cb6fddee26c0=1782695747; HMACCOUNT=5B22C2BEF2EF9320; sessionid=371wy9tw0s27h36n477hnp6wi7l0htex; Hm_lpvt_0d2227abf9548feda3b9cb6fddee26c0=1782698307'
|
||||
main(url,headers)
|
||||
@@ -0,0 +1,126 @@
|
||||
# '''
|
||||
# 请求参数经过特殊处理,适合JavaScript逆向入门练习
|
||||
# '''
|
||||
# import requests
|
||||
# import execjs
|
||||
#
|
||||
# def herder_data():
|
||||
# headers = {
|
||||
# 'Host': 'www.mashangpa.com',
|
||||
# 'Connection': 'keep-alive',
|
||||
# 'Pragma': 'no-cache',
|
||||
# 'Cache-Control': 'no-cache',
|
||||
# 'sec-ch-ua-platform': '"Windows"',
|
||||
# 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36',
|
||||
# 'sec-ch-ua': '"Google Chrome";v="149", "Chromium";v="149", "Not)A;Brand";v="24"',
|
||||
# 'sec-ch-ua-mobile': '?0',
|
||||
# 'Accept': '*/*',
|
||||
# 'Sec-Fetch-Site': 'same-origin',
|
||||
# 'Sec-Fetch-Mode': 'cors',
|
||||
# 'Sec-Fetch-Dest': 'empty',
|
||||
# 'Referer': 'https://www.mashangpa.com/problem-detail/2/',
|
||||
# 'Accept-Encoding': 'gzip, deflate, br, zstd',
|
||||
# 'Accept-Language': 'zh-CN,zh;q=0.9,chr;q=0.8',
|
||||
# #'Cookie': 'Hm_lvt_0d2227abf9548feda3b9cb6fddee26c0=1782695747; HMACCOUNT=5B22C2BEF2EF9320; sessionid=371wy9tw0s27h36n477hnp6wi7l0htex; Hm_lpvt_0d2227abf9548feda3b9cb6fddee26c0=1782698307'
|
||||
# }
|
||||
# return headers
|
||||
#
|
||||
# js_code = '''
|
||||
# function loadPage(pageNumber){
|
||||
# const timestamp = new Date().getTime()
|
||||
# const params = {
|
||||
# page: pageNumber,
|
||||
# _ts: timestamp,
|
||||
# };
|
||||
#
|
||||
# function encrypt(_0x277028) {
|
||||
# const _0x4d843e = _0x38addf;
|
||||
# let _0x2703a2 = dd['a'][_0x4d843e(0xd6)]['Utf8']['parse'](_0x277028),
|
||||
# _0x50fcf0 = dd['a'][_0x4d843e(0xd2)][_0x4d843e(0xc5)](_0x2703a2, key, {
|
||||
# 'mode': dd['a'][_0x4d843e(0xd1)]['CBC'],
|
||||
# 'padding': dd['a'][_0x4d843e(0xd7)]['Pkcs7'],
|
||||
# 'iv': iv
|
||||
# });
|
||||
# return _0x50fcf0['ciphertext'][_0x4d843e(0xcb)](CryptoJS[_0x4d843e(0xd6)][_0x4d843e(0xc6)]);
|
||||
# }
|
||||
# '''
|
||||
# ctx = execjs.compile(js_code)
|
||||
# url_path = ctx.call("encrypt", 5, 2)
|
||||
# print(url_path)
|
||||
|
||||
|
||||
|
||||
import time
|
||||
import json
|
||||
import binascii
|
||||
import requests
|
||||
import urllib3
|
||||
from Crypto.Cipher import AES
|
||||
from Crypto.Util.Padding import pad
|
||||
|
||||
# 屏蔽Fiddler/代理SSL警告
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
|
||||
# 固定加密参数(屠龙刀专用)
|
||||
KEY_RAW = "jo8j9wGw%6HbxfFn"
|
||||
IV_RAW = "0123456789ABCDEF"
|
||||
key = KEY_RAW.encode("utf-8")
|
||||
iv = IV_RAW.encode("utf-8")
|
||||
|
||||
# 接口基础配置
|
||||
problem_id = 5
|
||||
url = f"https://www.mashangpa.com/api/problem-detail/{problem_id}/data/"
|
||||
headers = {
|
||||
'Host': 'www.mashangpa.com',
|
||||
'Connection': 'keep-alive',
|
||||
'Pragma': 'no-cache',
|
||||
'Cache-Control': 'no-cache',
|
||||
'sec-ch-ua-platform': '"Windows"',
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/149.0.0 Safari/537.36',
|
||||
'sec-ch-ua': '"Chrome";v="149", "Not)A;Brand";v="24"',
|
||||
'sec-ch-ua-mobile': '?0',
|
||||
'Accept': '*/*',
|
||||
'Sec-Fetch-Site': 'same-origin',
|
||||
'Sec-Fetch-Mode': 'cors',
|
||||
'Sec-Fetch-Dest': 'empty',
|
||||
'Referer': f'https://www.mashangpa.com/problem-detail/{problem_id}/',
|
||||
'Accept-Encoding': 'gzip, deflate, br, zstd',
|
||||
'Accept-Language': 'zh-CN,zh;q=0.9',
|
||||
'Content-Type': 'application/json',
|
||||
# 替换你浏览器登录后的完整Cookie
|
||||
'Cookie': "Hm_lvt_0d2227abf9548feda3b9cb6fddee26c0=1782695747; HMACCOUNT=5B22C2BEF2EF9320; sessionid=371wy9tw0s27h36n477hnp6wi7l0htex; Hm_lpvt_0d2227abf9548feda3b9cb6fddee26c0=1782714143"
|
||||
}
|
||||
|
||||
def aes_encrypt(raw_json_str: str) -> str:
|
||||
"""对齐前端CryptoJS AES-CBC逻辑"""
|
||||
# 这里必须用参数名 raw_json_str
|
||||
data_bytes = raw_json_str.encode("utf-8")
|
||||
cipher = AES.new(key, AES.MODE_CBC, iv)
|
||||
enc_bytes = cipher.encrypt(pad(data_bytes, AES.block_size, style="pkcs7"))
|
||||
return binascii.hexlify(enc_bytes).decode("utf-8")
|
||||
|
||||
|
||||
def build_post_body(page: int) -> dict:
|
||||
"""生成加密后的请求体"""
|
||||
ts = int(time.time() * 1000)
|
||||
params = {"page": page, "_ts": ts}
|
||||
json_raw = json.dumps(params)
|
||||
xl_hex = aes_encrypt(json_raw)
|
||||
return {"xl": xl_hex}
|
||||
|
||||
# 分页遍历1~20求和
|
||||
total_sum = 0
|
||||
for page_num in range(1, 21):
|
||||
body = build_post_body(page_num)
|
||||
resp = requests.post(url, headers=headers, json=body, verify=False)
|
||||
res_json = resp.json()
|
||||
arr = res_json["current_array"]
|
||||
# 判断登录失效
|
||||
if isinstance(arr, str):
|
||||
print("Cookie过期,请重新抓取登录Cookie!")
|
||||
break
|
||||
page_sum = sum(arr)
|
||||
total_sum += page_sum
|
||||
print(f"第{page_num}页 | 数组:{arr} | 单页和:{page_sum}")
|
||||
|
||||
print(f"\n===== 1~20页全部总和:{total_sum} =====")
|
||||
Reference in New Issue
Block a user