首页
注册
登录
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请
登录
V2EX
›
asmoker
›
全部回复第 15 页 / 共 15 页
回复总数
281
1
...
6
7
8
9
10
11
12
13
14
15
❮
❯
2019-07-02 19:19:52 +08:00
回复了
xuyl
创建的主题
›
Python
›
爬取某头条 h5 端接口, 无论如何都拿不到数据, 姿势不对?
难道是这样?两年前的方法了……
def _gen_req_params():
"""
生成请求头条 URL 必要的密钥参数
:return:
"""
# 响应结果
params = {
'as': '479BB4B7254C150',
'cp': '7E0AC8874BB0985'
}
# 当前时间戳
timestamp = int(math.floor(int(round(time.time() * 1000)) / 1000))
now = hex(timestamp)
now_str_number = now[2:len(now)].upper()
now_md5 = hashlib.md5(str(timestamp).encode()).hexdigest().upper()
# 计算 as 和 cp 参数
if len(now_str_number) == 8:
as_pre = ''
cp_pre = ''
first_five_char = now_md5[0:5]
last_five_char = now_md5[:-5]
for i in range(5):
as_pre += first_five_char[i] + now_str_number[i]
for j in range(5):
cp_pre += now_str_number[j + 3] + last_five_char[j]
as_result = "A1" + as_pre + now_str_number[-3:]
cp_result = now_str_number[0:3] + cp_pre + "E1"
params = {
'as': as_result,
'cp': cp_result
}
return params
1
...
6
7
8
9
10
11
12
13
14
15
❮
❯
关于
·
帮助文档
·
博客
·
API
·
FAQ
·
实用小工具
·
5779 人在线
最高记录 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 12ms ·
UTC 02:42
·
PVG 10:42
·
LAX 18:42
·
JFK 21:42
Developed with
CodeLauncher
♥ Do have faith in what you're doing.