获取 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 (将#修改为@)