我需要下載可透過以下網址取得的資料:
http://www.arpalazio.net/main/aria/sci/basedati/chimici/BDchimici/RM/MedieGiornaliere/RM_PM2.5_ 2019年_gg.txt
要下載不同年份的數據,我需要更改url中的年份,如下所示紅色的。 我想在 JSL 中編寫一個循環,運行從 1990 年到 2021 年,並將資料放入表中。 我是 JSL 的新手,因此非常感謝這方面的任何幫助。
@Craige_Hales這非常有幫助並且節省了我很多時間。 多謝!!!
是的,開發人員工具使這比學習 HTML 表單更容易。
Using web browser developer tools to examine the link that was used to download a fileUsing web browser developer tools to examine the link that was used to download a file使用 Web 瀏覽器開發人員工具檢查用於下載文件的鏈接
此連結具有參數,您可以在使用 open() 打開它之前使用 JSL 修改這些參數。 FF 如上所示,chrome 類似,但排列方式不同。
您的原始連結請求 12 個月的數據。 網站不想發送那麼多,我停在 31jan 而不是 31dec。
據我所知,您無法使用 JMP 單擊網站中的元素,但您可以使用 HTTP 請求來獲取資料。 為此,您必須弄清楚請求是如何完成的(瀏覽器的開發人員工具可以對此有所幫助)。
為此,您需要一些東西:循環(for 循環)、建立 url 的方法(eval insert)、從 url 加載資料的方法(使用正確的參數開啟)以及組合資料的方法(連接)。
Names Default To Here(1);
//We can use Eval Insert to replace ^temp_year^ in the string
dl_url = "http://www.arpalazio.net/main/aria/sci/basedati/chimici/BDchimici/RM/MedieGiornaliere/RM_PM2.5_^temp_year^_gg.txt";
dt = New Table(); //table to collect results
//for-loop
For(i = 1990, i <= 2021, i++,
temp_year= Char(i);
year_url = Eval Insert(dl_url);
//downloaded first one file by hand -> opened in JMP to get Open with correct parameters and replaced file path with URL
Try(
dt_temp = Open(
year_url,
Import Settings(
End Of Line(CRLF, CR, LF),
End Of Field(Spaces, Space, CSV(0)),
Strip Quotes(1),
Use Apostrophe as Quotation Mark(0),
Use Regional Settings(0),
Scan Whole File(1),
Treat empty columns as numeric(0),
CompressNumericColumns(0),
CompressCharacterColumns(0),
CompressAllowListCheck(0),
Labels(1),
Column Names Start(1),
Data Starts(2),
Lines To Read("All"),
Year Rule("20xx")
)
);
dt << Concatenate(dt_temp, Append to first table(1));
Close(dt_temp, no save);
,
Show(exception_msg)
);
);
Concatenate 應該能夠透過建立缺失值來處理缺少的列,而 Try 是處理不存在的 URL 的相當簡單的方法(雖然有點懶)。