test.py 845 B

1234567891011121314151617181920212223242526272829303132
  1. import json
  2. import pandas as pd
  3. with open('data2.json', 'r') as f:
  4. data = json.load(f)
  5. try:
  6. goods = []
  7. items = data['items']
  8. for item in items:
  9. goods_model = item['item_data']['goods_model']
  10. goods_id = str(goods_model['goods_id'])
  11. goods_name = goods_model['goods_name']
  12. link_url = goods_model['link_url']
  13. if "卡奇尔" in goods_name:
  14. good = {
  15. "goods_id": goods_id,
  16. "goods_name": goods_name,
  17. "link_url": link_url
  18. }
  19. # 将 JSON 对象添加到 JSON 数组中
  20. goods.append(good)
  21. except (KeyError, TypeError) as e:
  22. print(f"Error parse value : {e}")
  23. list = None
  24. df = pd.DataFrame(goods)
  25. # 将 DataFrame 写入 Excel 文件
  26. df.to_excel('output.xlsx', index=False, engine='xlsxwriter')