[軟體熟悉度]:
使用者(已經有用R 做過不少作品)
[問題敘述]:
資料庫網站本身載入就不快,有時更會塞車,讀取網站的檔案或路徑時,
回傳讀取的連結(檔案或路徑)list,即便網站路徑存在還是會讀不到。
網站讀取如果快的時候可以完成,請見範例程式。
如果慢的時候,就算連結存在,會出現錯誤,當下我開網頁大約需要4分鐘。
程式約3秒出現錯誤訊息。錯誤訊息為:
Error in open.connection(x, "rb") : cannot open the connection。
因為希望程式能自動每日執行,不會卡在有時因網站loading慢而中止,有甚麼方式
可以讓程式等待網站呢?
[程式範例]:
成功的:
"http://tisvcloud.freeway.gov.tw/history/" %>>% (~ cat('Now the program is at
', ., "\n")) %>>%
read_html("UTF8") %>>% xml_find_all("//*[@id='form1']//table/tbody") %>>%
xml_find_all("//tr/td[1]/a") %>>% xml_text %>>%
when(identical(.Platform$OS.type, "windows") ~ stri_conv(., "UTF-8",
"Big5"), ~ .)
結果:
Now the program is at http://tisvcloud.freeway.gov.tw/history/
[1] "Parent Directory" "vd"
"TDCS_PINGLIN" "TDCS"
[5] "roadlevel" "motc20" "map"
...
[25] "1min_incident_data_1968.xml" "1968_incident.pdf"