测试URL:www.dxy.cn/bbs/newweb/…
# -*- coding: utf-8 -*-
import time
import requests
import hashlib
import random
headers = {
'authority': 'www.dxy.cn',
'pragma': 'no-cache',
'cache-control': 'no-cache',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="98", "Google Chrome";v="98"',
'accept': 'application/json',
'content-type': 'application/json;charset=utf-8',
'sec-ch-ua-mobile': '?0',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36',
'sec-ch-ua-platform': '"macOS"',
'sec-fetch-site': 'same-origin',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://www.dxy.cn/bbs/newweb/pc/board/148',
'accept-language': 'zh-CN,zh;q=0.9',
}
def get_serverTimestamp():
import requests
noncestr = str(random.randint(10000000, 99999999))
timestamp = str(int(time.time() * 1000))
sha1 = hashlib.sha1()
sha1.update(
'appSignKey=4bTogwpz7RzNO2VTFtW7zcfRkAE97ox6ZSgcQi7FgYdqrHqKB7aGqEZ4o7yssa2aEXoV3bQwh12FFgVNlpyYk2Yjm9d2EZGeGu3&'
f'noncestr={noncestr}&'
f'serverTimestamp=0×tamp={timestamp}'.encode('utf-8'))
sign = sha1.hexdigest()
params = (
('serverTimestamp', '0'),
('timestamp', timestamp),
('noncestr', noncestr),
('sign', sign),
)
response = requests.get('https://www.dxy.cn/bbs/newweb/sys/time-millis/info', headers=headers, params=params)
return str(response.json().get("data"))
def get_data():
noncestr = str(random.randint(10000000, 99999999))
timestamp = int(time.time() * 1000)
serverTimestamp = get_serverTimestamp()
timestamp = str(timestamp)
sha1 = hashlib.sha1()
sha1.update(
'appSignKey='
'4bTogwpz7RzNO2VTFtW7zcfRkAE97ox6ZSgcQi7FgYdqrHqKB7aGqEZ4o7yssa2aEXoV3bQwh12FFgVNlpyYk2Yjm9d2EZGeGu3&'
f'noncestr={noncestr}&'
f'postId=46124964&'
f'serverTimestamp={serverTimestamp}×tamp={timestamp}'.encode('utf-8'))
sign = sha1.hexdigest()
params = (
('postId', '46124964'),
('serverTimestamp', serverTimestamp),
('timestamp', timestamp),
('noncestr', noncestr),
('sign', sign),
)
response = requests.get('https://www.dxy.cn/bbs/newweb/post/detail', headers=headers, params=params)
print(response.text)
if __name__ == '__main__':
# get_serverTimestamp()
get_data()