有没有办法执行命令+;a是否使用Rselenium突出显示页面上的所有文本?还是用另一种方式突出显示页面上的所有文本?

有没有办法执行命令+;a是否使用Rselenium突出显示页面上的所有文本?还是用另一种方式突出显示页面上的所有文本?,r,web-scraping,rselenium,R,Web Scraping,Rselenium,也许使用像这样的sendKeysActiveElement函数 SendKeysActiveElement( 列表(键='命令\元',“U+0074”) ) U+0074是您可能感兴趣的小写“a”的UTF代码。它将以下代码作为“偷偷预览”发布在页面上 # Sneak preview of code for interacting with a web page with RSelenium # a proper blog post with explanation will follow. l

也许使用像这样的sendKeysActiveElement函数

SendKeysActiveElement( 列表(键='命令\元',“U+0074”) )

U+0074是您可能感兴趣的小写“a”的UTF代码。它将以下代码作为“偷偷预览”发布在页面上

# Sneak preview of code for interacting with a web page with RSelenium
# a proper blog post with explanation will follow.

library(RSelenium)
# make sure you have the server
checkForServer()

# use default server 
startServer()
remDr<-remoteDriver$new()


# send request to server
url<-"https://programs.iowadnr.gov/animalfeedingoperations/FacilitySearch.aspx?Page=0"
remDr$open(silent = TRUE) #opens a browser
remDr$navigate(url)


# identify search button and click
searchID<-'//*[@id="ctl00_foPageContent_SearchButton"]'
webElem<-remDr$findElement(value = searchID)
webElem$clickElement()

# identify the table
tableID<-'//*[@id="ctl00_foPageContent_Panel1"]/div[2]/table'
webElem<-remDr$findElement(value = tableID)

doc<-htmlParse(remDr$getPageSource()[[1]])

tabledat<-readHTMLTable(doc)[[17]]
tabledat[,]<-lapply(tabledat[,],
    function(x) gsub("ÃÂ", "", as.character(x)))
tabledat<-tabledat[-nrow(tabledat),-1]
# go to next page
nextID<-'//*[@id="ctl00_foPageContent_FacilitySearchRepeater_ctl11_PagePlus1"]'
webElem<-remDr$findElement(value = nextID)
webElem$clickElement()
#使用RSelenium与网页交互的代码预览
#一个适当的博客文章解释如下。
图书馆(资源库)
#确保你有服务器
checkForServer()
#使用默认服务器
startServer()

remDr正如Rachel所指出的,你可以使用她给出的许多链接中概述的按键。您可以向元素(html标记)发送按键。
body
html标记可用于发送到页面:

library(RSelenium)
rD <- rsDriver()
appURL <- "https://stackoverflow.com/questions/45123833/is-there-a-way-to-do-commanda-to-highlight-all-text-on-a-page-with-rselenium-o/45123917#45123917"
remDr <- rD$client
remDr$navigate(appURL)
# select the page 
bElem <- remDr$findElement("css", "body")
# send key press to page
bElem$sendKeysToElement(list(key = "control", "a"))
remDr$screenshot(display = TRUE)

# cleanup
rm(rD)
gc()
显示命令键被引用为
command\u meta
,因此在MAC(未测试)中,您可以使用:

bElem$sendKeysToElement(list(key = "command_meta", "a"))

在上述情况下。

这没有帮助。我希望能够向网页发送一个热键(apple+a),使其突出显示所有文本。@ghostrecon27重新阅读了吉姆·普兰特的文章(你显然还没有读过约翰·哈里森的文章,其中概述了向元素发送事件)。哈哈,你们两个都不能回答我的问题。你缺乏解决问题的技能,就像锤子敲螺丝钉一样。@ghostrecon27我有16.2k的代表;我解决了不少问题!另一方面,你似乎缺乏编码所需的许多技能(包括对问题的基本理解!)我比你有更多的街头代表,我们都知道这更重要。你是blogspot的约翰·哈里森吗?太好了……:)又不是我要找的。想象一下,有人打开浏览器,进入一个网站,只需按command+a。我不想刮去css元素——这对我试图实现的目标根本不起作用。这就是你如何“简单地”转到一个网站并使用selenium按下command+a。你不是在“刮”css元素。
sapply(selKeys, function(x) identical(x, '\ue03d'))
bElem$sendKeysToElement(list(key = "command_meta", "a"))