Created
November 28, 2019 06:23
-
-
Save tmizu23/58f1d8db8cd4a56f6dba3e09eba07a35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("RSelenium") | |
library("rvest") | |
library("tidyverse") | |
library("stringr") | |
browser = remoteDriver(remoteServerAddr = "localhost", port = 4444, browserName = "chrome") | |
browser$open() | |
for(page in 1:58){ | |
url <- paste0("http://gis.biodic.go.jp/webgis/sc-017.html?1st=",str_pad(page, 2, pad = "0")) | |
browser$navigate(url) | |
Sys.sleep(3) | |
pagesource <- browser$getPageSource() | |
page_html <- paste0("get_snap_page",page,".html") | |
write(unlist(pagesource), page_html) | |
} | |
####page 10の伐採跡地群落は空のページなので注意! | |
alldata<-NULL | |
for(page in 1:58){ | |
data<-read_html(paste0("get_snap_page",page,".html"),encoding = "sjis") %>% | |
html_nodes("#legend") %>% html_table() %>% .[[1]] | |
alldata<-rbind(alldata,data) | |
} | |
tidydata<-alldata %>% | |
mutate(中区分=replace(中区分,大区分==中区分,NA)) %>% fill(中区分) %>% | |
replace(is.na(.), "00") %>% replace(.=="", "00") %>% | |
separate(大区分,c("DAI_C","DAI_N")," ") %>% | |
separate(中区分,c("CHU_C","CHU_N")," ") %>% | |
separate(細区分,c("SAI_C","SAI_N")," ") %>% | |
replace(is.na(.), "") %>% | |
unite(HANREI_C,DAI_C,CHU_C,SAI_C,sep="") | |
write_csv(tidydata,"HP植生凡例一覧.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment