Вам нужно два сценария. Первый, приведенный ниже, проверяет, и если в случае Эта страница неправильно загрузила Google Maps. , печатает сообщение об ошибке, используя пакет уведомлений. Для ознакомления с основами RSelenium, пожалуйста, обратитесь к https://cran.r -project.org / web / packages / RSelenium / vignettes / basics.html .
Там написано, что есть три способа запуска Selenium Server. Я выбрал easist, второй - rsDriver.
# To get the message written I use the notifier package,
# https://github.com/gaborcsardi/notifier
library(notifier)
# To do the webscraping I use RSelenium
library(RSelenium)
# To check whether the string contains what I am after I prefer stringr
library(stringr)
rD <- rsDriver(verbose = FALSE)
remDr <- rD$client
remDr$navigate("https:...")
# Wait a little while it is busy with downloading everything
Sys.sleep(120)
# we scrape it and convert it to a character string
a <- XML::htmlParse(remDr$getPageSource()[[1]])
b <- as(a, "character")
# we check if the string has the error phrase.
result <- str_detect(b, "This page can't load Google Maps correctly")
# if yes, then the following error message is printed.
if (result == TRUE){notify(title = "ERROR",
msg = sprintf("This page can't load Google Maps correctly"))}
# to close the client and the server
remDr$close()
rD$server$stop()
Ниже приведен второй скрипт для автоматизации в определенные моменты времени от самого R с помощью пакета taskscheduler. В этом случае код выполняется каждые 5 минут.
library(taskscheduleR)
myscript <- "the place of the first script"
taskscheduler_create(taskname = "myfancyscript_5min", rscript = myscript,
schedule = "MINUTE", starttime = "09:10", modifier = 5)