使用MATLAB从Openweathermap.org刮取数据

问题描述 投票:0回答:1

目前我正在使用MATLAB从API中获取最大温度,最小温度,压力和湿度的openweathermap.org数据。我的问题是,无论我在url中指定了什么lat和lon,url都保持完全相同。这是我用于当前数据的API站点的链接:https://openweathermap.org/current

目前我正在尝试一种方法,我改变纬度和经度以匹配for循环中一个点的纬度和经度。我正在尝试将这些数据写入csv文件。写作进展顺利,我唯一的问题是,无论我如何更改URL,表格上的数据都保持不变。

clear all
close all
% Using data from https://openweathermap.org/history
% Inputs are the latitude and longitude.

%% Add the EPA Code

match_file = 'C:\Users\tadams15\Desktop\Matching_Sites.csv';
data = xlsread(match_file);
lat = data(:,1);
lon = data(:,2);
for i = 1:length(lat)
    latv = lat(i);
    lonv = lon(i);
    url = ['https://samples.openweathermap.org/data/2.5/weather?lat=',num2str(latv),'&lon=',num2str(lonv),'&appid=b6907d289e10d714a6e88b30761fae22'];
    tempmaxtarget = 'temp_max';
    tempmintarget = 'temp_min';
    prestarget = 'pressure';
    humtarget = 'humidity';

    tempmax = urlfilter(url,tempmaxtarget);
    tempmin = urlfilter(url,tempmintarget);
    pressure = urlfilter(url,prestarget);
    humidity = urlfilter(url,humtarget);
    input = [tempmin tempmax pressure humidity];
    dlmwrite('Site_Info.csv',input,'delimiter',',','-append');
end
matlab url web-scraping
1个回答
1
投票

我不使用MATLAB,我使用Python,所以我可以; t测试,但看起来你需要修复你的网址。

看起来你每次只是调用样本返回:

https://samples.openweathermap.org/data/2.5/weather

也许你想要?:

api.openweathermap.org/data/2.5/weather
© www.soinside.com 2019 - 2024. All rights reserved.