def get_all_event_json(server,area_id,function,version,cookies): print('Getting all event data.....') total_data = [] last_id = 0 is_end = False data_instant = data_dict.copy() data_instant['area'] = area_id data_instant['dtu_msg[query_type]'] = 6 data_instant['dtu_msg[res_type]'] = res_type_dict[function] data_instant['res_type'] = res_type_dict[function] data_instant['dtu_msg[limit]'] = 50 data_instant['dtu_msg[order_type]'] = 1 current_index = 0 last_len = 0 while (not is_end): current_index = current_index + last_len data_instant['dtu_msg[start_idx]'] = current_index r = requests.post( url_prefix_dict[version][server] + url_infix_dict[version][server] + url_suffix_dict[function], data=data_instant, cookies=cookies) try: result = json.loads(r.text) except: break is_end = result['extends']['is_end'] if function == 'shop': last_len = 50 else: last_len = len(result['rows']) total_data.extend(result['rows']) print('all event data ok') return total_data 将这段函数里面的json文件输出该怎么写
时间: 2024-03-09 17:49:58 浏览: 56
get_all_ip.zip_本地IP
你可以在函数的最后一行添加以下代码,将获取到的数据以 JSON 格式写入到文件中:
```
import json
with open('total_data.json', 'w') as f:
json.dump(total_data, f)
```
这样就会将 `total_data` 变量中的数据以 JSON 格式写入到名为 `total_data.json` 的文件中。注意:在使用 `json.dump` 函数时,需要将文件对象和要写入的数据作为参数传递进去。
阅读全文