RSelenium 无法识别元素
RSelenium not recognising element
我正在尝试从此页面抓取所有提供商:https://www.agedcareguide.com.au/nursing-homes/providers/vic
我在 Mac 上使用 RSelenium,方法是 运行 在终端中使用 Docker 执行以下代码:
docker run -d -p 4445:4444 selenium/standalone-firefox
然后当我 return 到 RStudio 和 运行 以下内容时:
remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4445L,
browserName = "firefox")
remDr$open()
remDr$navigate("https://www.agedcareguide.com.au/nursing-homes/providers/vic")
remDr$getTitle()
一切都很好。
然后我尝试使用以下方法获取元素:
provs <- remDr$findElement()
在括号内我使用了 XPath,CSS 选择器,我能想到的一切,但总是出现:
Error in match.arg(using) :
'arg' should be one of “xpath”, “css selector”, “id”, “name”, “tag name”, “class name”, “link text”, “partial link text”
有人知道我错在哪里吗?
部分解决方案...
和RSelenium
...
remDr$navigate(...)
Sys.sleep(20) #the page keeps loading for some time
page <- remDr$getPageSource()
然后,rvest
...
provs <- page[[1]] %>% read_html() %>%
html_node("#app > div > div.c-col-results > div:nth-child(3) > div > section") %>%
html_text()
经过一些整理(按 \n
拆分,删除空白)...
provs
[1] "AdventCare" "Providing nursing homes"
[3] "Alexandra Gardens SRS" "Providing nursing homes"
[5] "Allbright Manor" "Providing nursing homes"
[7] "Alliance Care Services Group" "Providing nursing homes"
etc...
希望这会帮助您入门,尽管这是一个棘手的问题!
我正在尝试从此页面抓取所有提供商:https://www.agedcareguide.com.au/nursing-homes/providers/vic
我在 Mac 上使用 RSelenium,方法是 运行 在终端中使用 Docker 执行以下代码:
docker run -d -p 4445:4444 selenium/standalone-firefox
然后当我 return 到 RStudio 和 运行 以下内容时:
remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4445L,
browserName = "firefox")
remDr$open()
remDr$navigate("https://www.agedcareguide.com.au/nursing-homes/providers/vic")
remDr$getTitle()
一切都很好。
然后我尝试使用以下方法获取元素:
provs <- remDr$findElement()
在括号内我使用了 XPath,CSS 选择器,我能想到的一切,但总是出现:
Error in match.arg(using) : 'arg' should be one of “xpath”, “css selector”, “id”, “name”, “tag name”, “class name”, “link text”, “partial link text”
有人知道我错在哪里吗?
部分解决方案...
和RSelenium
...
remDr$navigate(...)
Sys.sleep(20) #the page keeps loading for some time
page <- remDr$getPageSource()
然后,rvest
...
provs <- page[[1]] %>% read_html() %>%
html_node("#app > div > div.c-col-results > div:nth-child(3) > div > section") %>%
html_text()
经过一些整理(按 \n
拆分,删除空白)...
provs
[1] "AdventCare" "Providing nursing homes"
[3] "Alexandra Gardens SRS" "Providing nursing homes"
[5] "Allbright Manor" "Providing nursing homes"
[7] "Alliance Care Services Group" "Providing nursing homes"
etc...
希望这会帮助您入门,尽管这是一个棘手的问题!