使用 Rselenium 单击跨域 iframe 元素 [英] Click on cross domain iframe element using Rselenium

查看:23
本文介绍了使用 Rselenium 单击跨域 iframe 元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 R 版本 3.3.2.使用 Rselenium 包,我试图从这个网站上抓取一些数据:http://www.dziv.hr/en/e-services/on-line-database-search/patents/

I am using R, version 3.3.2. Using Rselenium package, I am trying to scrap some data from this website: http://www.dziv.hr/en/e-services/on-line-database-search/patents/

我正在使用 Rselenium,我的代码如下所示:

I am using Rselenium and my code looks like this:

selServ <- RSelenium::startServer(javaargs = c("-Dwebdriver.gecko.driver="C:/Users/Mislav/Documents/geckodriver.exe""))
remDr <- remoteDriver(extraCapabilities = list(marionette = TRUE))
remDr$open()
Sys.sleep(2)

# Simulate browser session and fill out form
remDr$navigate("http://www.dziv.hr/hr/e-usluge/pretrazivanje-baza-podataka/patent/")

这不起作用:

webel <- remDr$findElement(using = "xpath", "/input[@id = 'TB1']")

然后我想使用 switchToFrame() 函数切换到 iframe,但是 iframe 不包含 id.

Then I wanted to swith to iframe using switchToFrame() function, but the iframe does not contain id.

然后我有 tr 使用索引:webel <- remDr$switchToFrame(1) 但这只是返回 NULL

Then I have tr to use index: webel <- remDr$switchToFrame(1) but this just return NULL

另外,我认识到,iframe 有不同的域.

Also, I recognized, iframe has different domain.

是否可以从该网站获取数据?

Is it possible to svrap data from this web site?

推荐答案

您可以只选择第一个 iframe 并将其传递给 switchToFrame 方法:

You can just select the first iframe and pass it to the switchToFrame method:

webElem <- remDr$findElements("css", "iframe")
remDr$switchToFrame(webElem[[1]])
webel <- remDr$findElement(using = "xpath", "//input[@id = 'TB1']")

这篇关于使用 Rselenium 单击跨域 iframe 元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆