首页 > 解决方案 > 使用 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

但什么也没有发生!

你知道如何去标签«匹配»

非常感谢 !

标签: rweb-scrapingrselenium

解决方案


这对我有用:

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()


推荐阅读