Last active
November 10, 2015 23:18
-
-
Save kashitan/fa6f9afcca89410aa120 to your computer and use it in GitHub Desktop.
rvest::follow_linkサンプル
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(rvest) | |
page <- 1 | |
sesh <- html_session('[クローリングするURL]') | |
Sys.sleep(10) | |
repeat{ | |
sesh <- tryCatch(follow_link(sesh, "次の20件"), error=function(e)(return(NULL))) | |
message(Sys.time(), ' ', sesh$url) | |
page <- page + 1 | |
# "次の20件"がない or 10回進んだらループを抜ける | |
if(is.null(sesh) || page == 10) break | |
Sys.sleep(10) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment