0

我正在使用我的 RSelenium 从网络上迭代收集数据。我的代码的示例结构

`for (i in 1:100)
{
re$findElement(using='css', 'some id')$getElementText()
}`

但是当在网页中找不到元素时,它会抛出一个名为 NoSuchElement 的错误。

我想知道一个像这样工作的代码。

for (i in 1:100) { re$findElement(using='css', 'some id')$getElementText() if NoSuchElement is found, break the loop and come out without stopping the program }

我尝试使用 tryCatch,但没有成功。

4

1 回答 1

2

这个答案

解决了这个问题。使用 while 检查NoSuchElement异常错误。

于 2016-03-07T03:19:16.290 回答