2018年刚入行的时候被安排做这个数据采集,搞了一周没结果,现在回头看几分钟解决了
测试URL: mytoken.io/media
# -*- coding: utf-8 -*-
import time
import hashlib
import requests
headers = {
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36',
}
timestamp = str(int(time.time() * 1000))
code = hashlib.md5(f'{timestamp}9527{timestamp[:6]}'.encode(encoding='UTF-8')).hexdigest()
params = {
'type': '1',
'tag': 'news',
'need_pagination': '1',
'page': '1',
'size': '20',
'timestamp': timestamp,
'code': code,
'platform': 'web_pc',
'v': '1.0.0',
'language': 'zh_CN',
'legal_currency': 'CNY',
}
response = requests.get(
'https://api.mytokenapi.com/media/medialist',
headers=headers,
params=params
)
print(response.json())