- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
此页面的主菜单( linio )有 11 个链接。只对 9 感兴趣(那些具有灰色背景并且悬停时显示子菜单的)。
我想从 9 个选项中单击子菜单中的每个元素。期望的过程是:
1.-第一部分:“Celulares y 平板电脑”。
2.-转至:“Celulares y 智能手机”。请点击并查看此页面。
3.-提取一些数据(检查过,我已经能够做到这一点)。
4.-转到“Celulares y Tablets”中的下一个子菜单。即:“Accesorios Cellular”。
5.-提取一些数据,然后进入下一个子菜单。完成本节中的所有子菜单后,我将转到下一个大部分:“TV-Audio-y-Foto”。
依此类推,共有 9 个部分。
HTML结构
查看源代码,我得到了这个:
1.- 主标题:主标题位于“nav”标签内:
<nav id="headerMainMenu>
2.-“nav”标签内有一个“ul”,其中的每个“il”都有对应 9 个部分的“id”:
<nav id="headerMainMenu>
<ul>
<il id = "category-item-celulares-y-tablets"><a href="..."></il>
<il id = "category-item-celulares-y-tablets"><a href="..."></il>
<il id = "category-item-celulares-y-tablets"><a href="..."></il>
</ul>
</nav>
3.- 在 il 元素内部,有包含我们需要的链接的 div 元素:请注意 <a>
与类=“subnav__title”。
<nav id="headerMainMenu>
<ul>
<il id = "category-item-celulares-y-tablets"><a href="...">
<div class="col-3">
<a href="..."class="subnav__title">TV y Video</a>
</il>
<il id = "category-item-celulares-y-tablets"><a href="..."></il>
<il id = "category-item-celulares-y-tablets"><a href="..."></il>
</ul>
</nav>
4.- 使用 RSelenium 转到每个部分:
library(RSelenium)
library(rvest)
#start RSelenium
checkForServer()
startServer()
remDr <- remoteDriver()
remDr$open()
#navigate to your page
remDr$navigate("http://www.linio.com.pe/")
#Accesing the first submenu from "Category Celulares y Tablets
webElem <- remDr$findElement(using = 'css', value = "#category-item-celulares-y-tablets a.subnav__title")
webElem$sendKeysToElement(list(key = "enter"))
但是这样做会显示此错误:
> webElem$sendKeysToElement(list(key = "enter"))
Error: Summary: StaleElementReference
Detail: An element command failed because the referenced element is no longer attached to the DOM.
class: org.openqa.selenium.StaleElementReferenceException
*我认为这个question可能会有帮助。但我不明白。
**我认为我的 CSS 没问题。
最佳答案
我在 Python 中使用了以下代码。我确信它可以转换为您的语言:
def click_hidden(self, css_selector):
'''
Click on a hidden element using javascript.
Selenium will error if the element doesn't excist and if javascript fails
REASON: Selenium doesn't allow clicks on hidden elements since the user won't either
So be sure the element would be visible in normal uses!
'''
element = self.find_css(css_selector)
self.execute_script("$(arguments[0]).click();", element)
return element
关于RSelenium:单击不可见对象 - ElementNotVisibleException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32409851/
我已将 r 更新到最新版本,并再次安装了 Rselenium。 我尝试使用 rsDriver,但端口 4567 有问题。与 this 相同 错误回溯: rd <-rsDriver(verbose =T
我找到了@jdharrison 关于如何在 Windows 上使用 RSelenium 启动 Tor 的绝妙答案: https://stackoverflow.com/a/39048970/78373
我想使用 RSelenium 和 Firefox 浏览器从网站下载文件。 我做的一切都是正确的(导航,选择正确的元素并写下我想要的); 现在我单击“下载”按钮,然后会打开一个 Firefox 弹出窗口
我正在使用 RSelenium 构建一个包含有关经理信息的数据框。我在选择下拉列表中的元素时遇到问题。 我的代码如下: > require(RSelenium) > remDr remDr$open(
我不确定是不是因为我的网速很慢,但我正在尝试抓取一个在您向下滚动页面时加载信息的网站。我正在执行一个转到页面末尾的脚本,并等待 Selenium/Chrome 服务器加载其他内容。服务器确实更新并加载
我一整天都在使用 RSelenium,但仍然到处遇到障碍。我当前的问题是使用代码 WebElemReports$clickElement() 单击链接并打开一个新窗口。我尝试调整“about:conf
如何使用 Rselenium 抓取下拉列表中的所有选项值? 页面源代码示例: Area 1 Area 2 Area 3 Area 4 Area 4 想要的结果是一个向量,每个值都是一个元素。例如,
我一整天都在使用 RSelenium,但仍然到处遇到障碍。我当前的问题是使用代码 WebElemReports$clickElement() 单击链接并打开一个新窗口。我尝试调整“about:conf
如何使用 Rselenium 抓取下拉列表中的所有选项值? 页面源代码示例: Area 1 Area 2 Area 3 Area 4 Area 4 想要的结果是一个向量,每个值都是一个元素。例如,
我将如何并行运行RSelenium。 以下是并行使用 rvest 的示例 library(RSelenium) library(rvest) library(magrittr) library(for
我正在尝试使用 RSelenium。这是我正在做的事情: library(RSelenium) driver<- rsDriver(browser=c("chrome")) remDr <- dri
我在 RSelenium 中使用以下代码来打开浏览器。在我关闭浏览器,甚至通过运行 remDr$close() 关闭处理程序后,该端口仍在使用中。我必须转到终端并手动终止该进程,以便同一端口可用。是否
我是 RSelenium 的新手,在使用“Introduction Vignette”中的以下示例时遇到了问题: remDr$navigate("http://www.r-project.org")
我使用 RSelenium 填写网络表单。要从下拉列表中选择一个选项,我使用以下命令: xpathoption <- paste0("//select[@id = '",samplepatient[p
我尝试使用以下命令安装和运行 R Selenium 包的简单示例: install.packages("RSelenium") library("RSelenium") startServer() c
我正在尝试使用 RSelenium 抓取网站。但是,当我想连接到 Selenium 服务器时遇到问题。 假设我使用 rsDriver() 命令启动 selenium 服务器和浏览器: rsDriver
在 Linux 上,RSelenium/Selenium似乎行为不正常。我手动启动服务器,它似乎启动正常。有时我可以从我的 R session 连接到它,有时我会收到错误消息。我还不能查明原因:相同的
SO (Question 1) 中已经提出了一些与此类似的问题。 , (Question 2) ,但没有一个得到答复(最后一个有@jdharrison 的相关评论,指示 OP 提出问题)。这是我的问题
我希望使用 RSelenium 将一些基因名称输入到一个在线存储库中,该存储库为所述基因创建功能注释热图。 但是,我正在努力研究如何将基因列表输入到文本框中以生成热图。 这是文本框和与之关联的 htm
我正在尝试使用RSelenium通过按钮捕获网页上可用的csv。相关的html是: Download 我可以通过其类选择i元素: remDr$findElement(using = 'css sel
我是一名优秀的程序员,十分优秀!