[問題] 抓取氣象局地震資料
看板R_Language作者hanglong (小煥)時間5年前發表 (2019/09/11 03:46), 5年前編輯推噓2(2推 0噓 8→)留言10則, 3人參與, 5年前最新討論串1/2 (看更多)
[問題類型]:
程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來)
我想要抓台灣每次地震,固定地點的震度
[軟體熟悉度]:
新手(沒寫過程式,R 是我的第一次)
[問題敘述]:
以台灣時間09-11 05:24的地震為例,它的網址是:
https://scweb.cwb.gov.tw/zh-tw/earthquake/details/2019091105245636
以此網址為例,我可以擷取固定地點,例如 玉山 的資料
但是地震發生很多次,每次的網址都不一樣,不可能每次都手動抓網址,
再用R抓到玉山的震度。
我在地震資料的網址中,可以從原始碼中看到每個地震的連結,
https://scweb.cwb.gov.tw/zh-tw/earthquake/data/
因此,如果有辦法可以從這裡擷取到每次地震的網址,
應該就可以完成我的需求,但是這個網址的部分,不知道該如何擷取,
在請版上的各位先進幫忙,謝謝。
[程式範例]:
在https://scweb.cwb.gov.tw/zh-tw/earthquake/details/2019091105245636之下
利用以下程式,可以看到玉山的震度:
data <-
read_html("https://scweb.cwb.gov.tw/zh-tw/earthquake/details/2019091105245636")
ths <- xml_find_all(data, "//div/ul/li")
xml_text(ths)[substring(xml_text(ths),1,2) == "玉山"]
[1] "玉山 1"
但在https://scweb.cwb.gov.tw/zh-tw/earthquake/data/之下,
我想要用一樣的方式,至少先擷取出網址的位置,結果什麼都沒有...
程式如下:
data <-
read_html("https://scweb.cwb.gov.tw/zh-tw/earthquake/data/")
ths <- xml_find_all(data, "//div/table/tbody/tr/td/a")
xml_text(ths)
character(0)
[環境敘述]:
請提供 sessionInfo() 的輸出結果,
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 LC_CTYPE=Chinese
(Traditional)_Taiwan.950 LC_MONETARY=Chinese (Traditional)_Taiwan.950
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] xml2_1.2.2 curl_3.3 swirl_101.5.9
loaded via a namespace (and not attached):
[1] Rcpp_1.0.2 pvm_0.4.2.4 later_0.8.0 digest_0.6.20
bitops_1.0-6 R6_2.4.0 jsonlite_1.6 magrittr_1.5 httr_1.4.0
rlang_0.4.0 stringi_1.4.3
[12] promises_1.0.1 testthat_2.1.1 tools_3.6.1 stringr_1.4.0
RCurl_1.95-4.12 httpuv_1.5.1 yaml_2.2.0 compiler_3.6.1
[關鍵字]:
中央氣象局 地震
--
愛狗人士:打狗的人都去死啦!!!!!(#‵′)凸
高雄人:靠北喔!!!!!!!!!!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.227.245.73 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1568173572.A.E8F.html
→
09/11 12:51,
5年前
, 1F
09/11 12:51, 1F

→
09/11 12:52,
5年前
, 2F
09/11 12:52, 2F

不好意思,我在network有找到每個的網址,但不曉得這些網址可否抓下來?
這樣我才有辦法利用這些網址,加上上方的程式碼,抓到所需要的資料。
推
09/11 12:57,
5年前
, 3F
09/11 12:57, 3F
→
09/11 12:58,
5年前
, 4F
09/11 12:58, 4F
不好意思,我有申請會員,也有試著去抓Open API的資料,但是一直出現錯誤
所以依然沒有辦法看到資料。
※ 編輯: hanglong (125.227.245.73 臺灣), 09/11/2019 15:02:07
→
09/11 15:26,
5年前
, 5F
09/11 15:26, 5F
→
09/11 15:26,
5年前
, 6F
09/11 15:26, 6F
→
09/11 15:35,
5年前
, 7F
09/11 15:35, 7F
→
09/11 15:38,
5年前
, 8F
09/11 15:38, 8F
推
09/11 16:00,
5年前
, 9F
09/11 16:00, 9F
→
09/11 16:00,
5年前
, 10F
09/11 16:00, 10F
感謝您提供的資料 內容非常的詳細 不過看起來中央氣象局api的資料
只能抓到最近的一次地震資料 我想要看前面幾次的地震資料 就找不到了QQ
※ 編輯: hanglong (125.227.245.73 臺灣), 09/11/2019 16:52:27
討論串 (同標題文章)
R_Language 近期熱門文章
PTT數位生活區 即時熱門文章
13
32