使用 RSelenium 和日历格式选择日期
Date Picking with RSelenium and Calendar Format
我想用 RSelenium 抓取票价。是否可以按日历日期格式输入密钥(见附图)。网站上的元素如下所示:
"<span class="flatpickr-day today selected" aria-label="November 12, 2021" aria-current="date" tabindex="-1">12</span>"
我目前使用的代码:
# go to rail service website
remDr$navigate("https://www.bahn.de")
# accept cookies
webElems <- remDr$findElements(using = "xpath", "//button[starts- with(@class, 'btn js-accept-all-cookies')]")
unlist(lapply(webElems, function(x) {x$getElementText()}))
webElems[[1]]$clickElement()
Sys.sleep(10) # wait for page loading
# Fill out forms
from <- "Berlin Hbf"
to <- "Köln Hbf"
day <- "14.11.2021"
time <- "16:00"
remDr$findElement(using = "id", value = "js-auskunft-autocomplete-from")$sendKeysToElement(list(from))
remDr$findElement(using = "id", value = "js-auskunft-autocomplete-to")$sendKeysToElement(list(to))
从这里开始,我迷路了,在采摘的日子里,也在时间上。
尝试这样的事情:
library(RSelenium)
remDr <- remoteDriver(
remoteServerAddr = "localhost",
port = 4445L,
browserName = "firefox"
)
remDr$open()
remDr$navigate("/foo.html")
remDr$navigate("http://www.example.com") # your url
remDr$findElements(using = 'xpath', "//span[@aria-label='November 12, 2021']")[[1]]$clickElement()
我想用 RSelenium 抓取票价。是否可以按日历日期格式输入密钥(见附图)。网站上的元素如下所示:
"<span class="flatpickr-day today selected" aria-label="November 12, 2021" aria-current="date" tabindex="-1">12</span>"
我目前使用的代码:
# go to rail service website
remDr$navigate("https://www.bahn.de")
# accept cookies
webElems <- remDr$findElements(using = "xpath", "//button[starts- with(@class, 'btn js-accept-all-cookies')]")
unlist(lapply(webElems, function(x) {x$getElementText()}))
webElems[[1]]$clickElement()
Sys.sleep(10) # wait for page loading
# Fill out forms
from <- "Berlin Hbf"
to <- "Köln Hbf"
day <- "14.11.2021"
time <- "16:00"
remDr$findElement(using = "id", value = "js-auskunft-autocomplete-from")$sendKeysToElement(list(from))
remDr$findElement(using = "id", value = "js-auskunft-autocomplete-to")$sendKeysToElement(list(to))
从这里开始,我迷路了,在采摘的日子里,也在时间上。
尝试这样的事情:
library(RSelenium)
remDr <- remoteDriver(
remoteServerAddr = "localhost",
port = 4445L,
browserName = "firefox"
)
remDr$open()
remDr$navigate("/foo.html")
remDr$navigate("http://www.example.com") # your url
remDr$findElements(using = 'xpath', "//span[@aria-label='November 12, 2021']")[[1]]$clickElement()