请你将下面这个接口的数据爬取下来并且以csv的格式输出,并突出字段lat和lng,并且写出python代码,这是接口https://gpminvestments.com/wp-json/wpgmza/v1/features/base64eJyrVkrLzClJLVKyUqqOUcpNLIjPTIlRsopRMo9R0gEJFGeUFni6FAPFomOBAsmlxSX5uW6ZqTkpELFapVoABk8WwA
时间: 2023-02-26 10:00:08 浏览: 86
用python给csv里的数据排序的具体代码
下面是python代码来爬取上述接口的数据,并以csv格式输出:
```
import requests
import csv
url = "https://gpminvestments.com/wp-json/wpgmza/v1/features/base64eJyrVkrLzClJLVKyUqqOUcpNLIjPTIlRsopRMo9R0gEJFGeUFni6FAPFomOBAsmlxSX5uW6ZqTkpELFapVoABk8WwA"
response = requests.get(url)
data = response.json()
with open('output.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(['lat', 'lng'])
for feature in data:
writer.writerow([feature['lat'], feature['lng']])
```
该代码首先通过`requests`库的`get`方法请求接口数据,然后使用`json`方法解析为Python字典。接下来,代码使用csv库写入数据到文件`output.csv`中,并突出字段`lat`和`lng`。
阅读全文