m0_56132761
2021-04-24 10:44
采纳率: 100%
浏览 99

python JsondecodeError该怎么解决,求大佬帮忙


 
import requests
import json
if __name__ == '__main__':
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36'
    }
    id_list = []#存储企业的id
    all_data_list = [] #存储所有企业的详情数据

    #批量获取不同企业的id值
    url = 'http://scxk.nmpa.gov.cn:81/xk/'
    for page in range(1,7):
        page = str(page)
        data={'on': 'true',
              'page': '1',
              'pageSize': '15',
              'productName':'',
              'conditionType':'1',
              'applyname':'',
              'applysn':''}


        json_ids = requests.post(url=url ,headers=headers,data=data).json()
        for dic in json_ids['list']:
            id_list.append(dic['ID'])

#获取企业详情数据'
    post_url='http://scxk.nmpa.gov.cn:81/xk/itownet/portalAction.do?method=getXkzsById'
        for id in id_list:
            data = {
                'id':id
    }
        detail_json = requests.post(url=post_url,headers=headers,data=data).json()
    #print(detail_json)
        all_data_list.append(detail_json)
    #持久化存储all data list
    fp= open('./allData.json','w',encoding='utf-8')
    json.dump(all_data_list,fp=fp,ensure_ascii=False)
    print('over')

 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

5条回答 默认 最新

相关推荐 更多相似问题