r - 使用 RSelenium 更改网站上的 onglet
问题描述
我正在使用 R selenium 在网站上抓取数据: https ://iwas.ophardt.online/en/biography/athlete/BURDON-Renata
我需要找到一个解决方案来浏览页面并转到“匹配”选项卡这是 HTML 页面源代码的一部分(我认为这是最重要的部分):
< div role="tabpanel" class="tab-pane" id="results">
< div role="tabpanel" class="tab-pane" id="matches">
< a href="#matches" aria-controls="results" class="nav-link" role="tab">Matches < /a>
这是我的代码:
library(RSelenium)
URL = "https://iwas.ophardt.online/en/biography/athlete/BURDON-Renata"
remote_driver <- driver[["client"]]
remote_driver$open() #open the navigator
remote_driver$navigate(URL) # go to the website
MATCHES = remote_driver$findElement(using = 'id', value = "results") # find the good tab
MATCHES$clickElement() #click on the good tab to change the page
但什么也没有发生!
你知道如何去标签«匹配»
非常感谢 !
解决方案
这对我有用:
library(RSelenium)
URL = 'https://iwas.ophardt.online/en/biography/athlete/BURDON-Renata'
driver <- RSelenium::rsDriver(browser = 'firefox', port = 4321L)
remote_driver <- driver[['client']]
remote_driver$open()
remote_driver$navigate(URL)
MATCHES = remote_driver$findElements(using = 'class', value = 'nav-link')
# Navigate to different tabs by adjusting the index in MATCHES:
MATCHES[[8]]$clickElement()
推荐阅读
- android - 访问mysql时无法补偿时差
- java - 无法移除 Camel Quartz 路线
- javascript - 在 DOM 中呈现表格后,AngularJS 将带有链接的单元格链接到表格中
- sql - 仅使用 select 语句模拟表
- reactjs - 无法解析 '@material-ui\core\Box' 中的 '@material-ui/styles/styled'
- java - 从项目和变量替换生成 Maven 原型
- asp.net-core-mvc - ASP.NET Core MVC 2.2 进程内托管 - 请求中止 CancellationToken 不起作用
- vba - 查找/替换 OLE 链接的问题
- python - 有没有办法将装饰器的返回值传递给函数 args?
- r - 您如何将 R devtools::install_git 与 TFS 托管的 Git Repo 一起使用?