从API读取数据并将其保存到python上的csv文件中

时间:2018-07-18 06:16:17

标签: python python-3.x

在将我从api读取的数据保存为csv格式时,我无法将其导出

import requests
import csv

api_address='http://api.openweathermap.org/data/2.5/weather?appid=c813d30c0e935c06d54403f3b77bb104&q='

city = input('City Name :')

url = api_address + city

json_data = requests.get(url).json()

with open('people.csv','w') as csvfile:

    writer = csv.writer(csvfile)

    for item in  json_data:

       writer.writerow(item)

0 个答案:

没有答案