qian78740300
  我大步向前i~
2021-01-21 21:26

关于pytho的for循环遍历报错

  • python
import requests
import json
if __name__ == "__main__":
    #爬主页ID
    url = 'http://scxk.nmpa.gov.cn:81/xk/itownet/portalAction.do?method=getXkzsById'
    
    user = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36 Edg/87.0.664.75'
    }
    

    data = {
        'on': 'true',
        'page':'1',
        'pageSize': '15',
        'productName':'',
        'conditionType': '1',
        'applyname':'',
        'applysn':'',
    }
    paqu = requests.post(url=url,headers=user,data=data).json()
    ids = []
    for fp in paqu['list'] :
        ids.append(fp['ID'])
    #json.dump(paqu,fp=fp,ensure_ascii=False)
    #fp = open('jieguo.json', 'w', encoding='utf-8')
    print(ids)

for循环遍历python报错

Traceback (most recent call last):
  File "F:\Python\pythonProject1\爬虫\化妆品许可爬取.py", line 29, in <module>
    for fp in paqu['list'] :
KeyError: 'list'

这是哪里的问题?

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答