【发布时间】:2021-01-08 08:24:36
【问题描述】:
我对 RSelenium 很陌生。我有一个芬兰公司的列表,我想在网页https://tietopalvelu.ytj.fi/yrityshaku.aspx?kielikoodi=3上提取对应的Business ID
我的 R 代码的简单版本如下:
library(RSelenium)
name_company <- c("nokia", "test")
driver <- rsDriver(browser= 'firefox', port = 16L)
remote_driver <- driver[["client"]]
remote_driver$navigate("https://tietopalvelu.ytj.fi/yrityshaku.aspx?kielikoodi=3")
input1 <- remote_driver$findElement(using = 'id', value = '_ctl0_cphSisalto_hakusana')
input1$sendKeysToElement(list(name_company[1])) # Name of the company
button_element1 <- remote_driver$findElement(using = 'id', value = '_ctl0_cphSisalto_sanahaku')
button_element1$clickElement() # Tick the box "word search"
button_element2 <- remote_driver$findElement(using = 'id', value = '_ctl0_cphSisalto_Hae')
button_element2$clickElement()
output <- remote_driver$findElement(using = "id", value="search-result")
output <- output$getElementText() # output including Business ID
当公司名称为“nokia”(在我的示例中为向量的第一个元素)时,它运行良好,但当它为“test”时,我得到对话框:“没有通过搜索选项找到匹配项”。
我想在我拥有的所有公司名称的向量上循环这段代码。 (例如 c("nokia", "kone", "blabla", ...) ) 如何保证循环不被对话框停止? 我希望它很清楚。
谢谢。
亚历克西斯
【问题讨论】:
标签: r popup try-catch rselenium