使用 Python 下载 json 文件或 Curl 不起作用

Download a json file using Python or Curl not working

使用 Python 或 Curl 下载 json 文件无效 url 此处:

https://api.nasdaq.com/api/screener/stocks?tableonly=true&limit=25&offset=0&download=true

import requests

json_data = {

'tableonly': 'true',
'limit':'25',
'offset':'0',
'download':'true'
}

headers = {
            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:99.0) Gecko/20100101 Firefox/99.0',
            'Accept': '*/*',
            'Accept-Encoding': 'gzip, deflate',
            'Accept-Language': 'en-US,en;q=0.5',
            'Content-Type': 'application/json',
            'platform': 'web',
            'hl': 'en',
            'os': 'web',
            'osv': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:99.0) Gecko/20100101 Firefox/99.0',
            'app': 'global',
            'lzone': 'dc_core_r001',
            'ph': 'MacOS Firefox',
            'locale': 'eng',
           # 'reqid': req_id,
            'device-type': 'Web'
            }

pos = requests.get('https://api.nasdaq.com/api/screener/stocks', json=json_data,headers=headers)

#print("content-type: application/json\n\n")
print("content-type: text/html\n\n")
print(pos)

您目前正在将 params 密钥作为 JSON 正文发送,请改用 params。

response = requests.get('https://api.nasdaq.com/api/screener/stocks', params=json_data, headers=headers)