如何解决获取 RSelenium 中的当前网址
我在 R 中有一个代码,我在其中使用 Selenium 从 Google 地图获取 URL。但它不起作用:
for (i in 1:dim(Coord_t)[1])
{
remDr$navigate("https://www.google.ro/maps") # navigates to webpage
# select CNP field
option <- remDr$findElement(using='xpath',"//*[@id='searchBoxinput']")
option$highlightElement()
option$clickElement()
option$sendKeystoElement(list(Coord_t$Conc[i]))
#press key
webElem <- remDr$findElement(using = 'css',"#searchBox-searchbutton")
webElem$highlightElement()
webElem$clickElement()
remDr$setTimeout(type = "page load",milliseconds = 10000)
Coord_t$Url[i] = remDr$getcurrenturl()
}
Coord$Conc[i]
它是餐厅、酒店等的简单名称。
我得到第一个 URL,然后只得到:"https://www.google.ro/maps"
。
我也尝试过:webElem$getcurrenturl()
和 option$getcurrenturl()
但它不起作用。
我就是想不通这里出了什么问题。
谢谢!
编辑:我发现问题出在“页面加载”上。看来我必须设置超时才能等待页面加载。我用 setTimeout
做了这个,但没有用。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。