r - 当我想在RSelenium中获得“没有html标签”时如何返回
问题描述
我正在抓取 RSelenium 的一些社区帖子。
使用 clickElement() 进入文章 url,并使用 goBack() 返回第一个屏幕。
但是我在进入特定文章时遇到了问题,该文章已被删除。
在第一个屏幕上,列表中有一篇文章,但是当我 clickElement() 那个特定文章时,它显示“文章已删除”,然后重定向到其他 url。
所以我得到错误,它停止工作。
这是我的代码。
for(i in 1:25){
tryCatch({
title_url <- mybrowser$findElement('xpath', paste0('//*[@id="container"]/div/section[2]/div[1]/div[2]/ul/li[',i,']/a'))
title_url$clickElement()
Sys.sleep(sample(1:3,1))
html <- mybrowser$getPageSource()[[1]]
post_html <- read_html(html)
title <- post_html %>% html_node('.title_subject') %>% html_text('span')
datetime <- post_html %>% html_node('.gall_date') %>% html_text()
content <- post_html %>% html_node(xpath='//*[@id="container"]/section/article[2]/div[1]/div/div[1]/div[1]/div[2]') %>% html_text()
mybrowser$goBack()
})
}
无论您遇到什么错误,我都希望使用 goBack() 函数。
错误喜欢
- 如果没有我期望的 html 标签。
- 重定向到我没想到的其他网址。
等等
请帮我 :(
解决方案
推荐阅读
- google-cloud-platform - 哪些 GCP 服务可用于点播视频流?
- android-studio - 从另一个活动打印
- excel - 我可以将 InternetExplorer.document 写入另一个 InternetExplorer 窗口吗?
- mysql - 架构错误:错误:插入语句中的 ER_PARSE_ERROR
- python - Python:乘以溢出
- c# - 添加评论时的 ExecuteNonQuery() 不会
- ios - 广告横幅出现在某些 ViewController 的工具栏下
- bootstrap-4 - bootstrap 响应式表 td 内容剪辑
- google-cloud-platform - 更改 Google Cloud Platform 上的 GPU 配额
- c# - 使用正则表达式更改
文本 到文本