r - 在 Rselenium 中处理弹出的身份验证窗口
问题描述
这个社区中的任何人都知道在使用 RSelenium 进行网络抓取时如何在弹出窗口中处理(如何输入用户名和密码)?我正在尝试登录以下数据门户并自动进行批量下载。网页:https://land.copernicus.vgt.vito.be/PDF/portal/Application.html#Browse;Root=512260;Collection=1000084;Time=NORMAL,NORMAL,-1,,,-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()
推荐阅读
- nginx - 如何使用 helm 图表获取 kubernetes ingress-nginx 的自定义错误页面?
- php - Woocommerce如何展示产品有两个类别,其中一个应该是常见的
- video - 如何使用 FFMPEG 将视频转换为多个名声?
- docker - 连接期间的 Docker 错误:发布 http://docker:2375/v1.24/auth
- javascript - 当标签中使用 nunjucks 时,gulp browser-sync 不会重新加载页面
- node.js - 我无法捕获 alexa 技能事件(已禁用)请求
- testing - 如何使用应用商店服务器通知实现应用购买
- amazon-web-services - 限制 aws sqs:ListQueues 的权限
- javascript - 如何从 ASP.NET 中的 HTML 表单(使用 Html.EnumDropDownListFor)获取值?
- python-3.x - 将日志从 EMR 集群保存到 Amazon S3 会引发错误“Ami 版本不支持最新的 RPM”