【问题标题】:Handling pop-up Authentication windows in Rselenium在 Rselenium 中处理弹出的身份验证窗口
【发布时间】:2021-04-04 07:27:22
【问题描述】:

这个社区中是否有人知道在使用 RSelenium 进行网络抓取时如何在弹出窗口中处理(如何输入用户名和密码)?我正在尝试登录以下数据门户并自动进行批量下载。 网页:https://land.copernicus.vgt.vito.be/PDF/portal/Application.html#Browse;Root=512260;Collection=1000084;Time=NORMAL,NORMAL,-1,,,-1,,

【问题讨论】:

  • 您提供的链接已损坏(单击它时会弹出一条消息:“消息:(TypeError):无法读取未定义的属性'j'”),我也认为您有括号中的错字,不确定您要在此处说什么,请尝试编辑它。
  • 这很奇怪......当点击它时链接工作正常。当使用 Rselenium 报废时弹出身份验证窗口时,括号应为...(如何键入用户名和密码)。我正在尝试以编程方式访问和下载一些基于卫星的植被产品:land.copernicus.vgt.vito.be
  • 您可以使用较短的xpath //*[@id="login"]//*[@id="password"] 作为用户名和密码。

标签: r rselenium docker-selenium


【解决方案1】:

通常,我会从检查网页中复制 xpath 并使用它来查找元素 - 就像我在这里所做的那样:

library(RSelenium)
library(netstat)

rD <- rsDriver(port = free_port(), browser = 'chrome', 
               chromever = "96.0.4664.45",  
               verbose = F)

remDr <- rD[["client"]]

# navigate - I used the url from your comment 
remDr$navigate("https://land.copernicus.vgt.vito.be/PDF/portal/Application.html#Home")

# find the login element
l <- remDr$findElement(using = "id", "login")
# there it is
l$highlightElement(); l$clickElement() # pops up the box to enter credentials 
  

# find the username
l1 <- remDr$findElement(using = "xpath", "/html/body/div[13]/div/table/tbody/tr[2]/td[2]/div/div/form/table/tbody/tr[1]/td[2]/input")
# there it is 
l1$highlightElement()
# sendkeys for username
l1$sendKeysToElement(list("username")) # replace with your username 

# find the password
l2 <- remDr$findElement(using = "xpath", "/html/body/div[13]/div/table/tbody/tr[2]/td[2]/div/div/form/table/tbody/tr[2]/td[2]/input")
# there it is 
l2$highlightElement()
# sendkeys to password
l2$sendKeysToElement(list("password"))

# login 
l3 <- remDr$findElement(using = "xpath", "/html/body/div[13]/div/table/tbody/tr[2]/td[2]/div/div/form/table/tbody/tr[5]/td/button[1]")
# there it is
l3$highlightElement(); l3$clickElement()

【讨论】:

  • 我试过这些都不起作用,不幸的是我不能告诉你为什么!
猜你喜欢
  • 1970-01-01
  • 2017-12-24
  • 2016-05-11
  • 2019-01-22
  • 1970-01-01
  • 2020-11-25
  • 1970-01-01
  • 2017-04-23
  • 1970-01-01
相关资源
最近更新 更多