[問題] 下載氣象局監測站CSV檔

作者: j2225653 (水中魚)   2019-10-17 17:48:21
問題:
[問題類型]:
程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來)
[軟體熟悉度]:
新手(沒寫過程式,R 是我的第一次)
[問題敘述]:
想要寫自動化下載氣象局監測資料CSV檔的腳本,但光單純下載一個連結的CSV檔卻跟
單純連結手動點選下載的CSV檔內容不同
[程式範例]:
testurl =
"https://e-service.cwb.gov.tw/HistoryDataQuery/YearDataController.do?
command=viewMain&station=466950&stname=%25E5%25BD%25AD%25E4%25BD%25B3
%25E5%25B6%25BC&datepicker=2018"
download.file(url = testurl,destfile = "C:/DATA/4669502018.csv",method =
"curl")
[環境敘述]:
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Traditional)_Taiwan.950
[2] LC_CTYPE=Chinese (Traditional)_Taiwan.950
[3] LC_MONETARY=Chinese (Traditional)_Taiwan.950
[4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Traditional)_Taiwan.950
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RCurl_1.95-4.12 bitops_1.0-6 RSQLite_2.1.2
loaded via a namespace (and not attached):
[1] bit_1.1-14 compiler_3.6.1 backports_1.1.5 DBI_1.0.0
[5] tools_3.6.1 memoise_1.1.0 Rcpp_1.0.2 bit64_0.9-7
[9] vctrs_0.2.0 blob_1.2.0 zeallot_0.1.0 digest_0.6.21
[13] rlang_0.4.0
[關鍵字]:
氣象局
作者: celestialgod (天)   2019-10-17 17:57:00
因為你的網址不是下載CSV 他下載CSV是JS觸發的https://i.imgur.com/bhFkL3Y.png
作者: j2225653 (水中魚)   2019-10-17 17:57:00
喔我耍笨了原來那個網址是觸發匯出CSV,不是下載連結...
作者: celestialgod (天)   2019-10-17 17:58:00
自己把MyTable抓下來就好了自己貼回去網址列試試看~~ 便知
作者: j2225653 (水中魚)   2019-10-17 17:59:00
請問C大知道怎麼下載到JS觸發的檔案呢?好 我試試看抓MYTABLE

Links booklink

Contact Us: admin [ a t ] ucptt.com