2017-07-16 5 views

答えて

1

あなたは興味のthis article from zevross.comを見つけることができます。

# FUNCTION from help for chartr 
capwords<-function(s, strict = FALSE) { 
    cap<-function(s) paste(toupper(substring(s, 1, 1)), 
     {s<-substring(s, 2); if(strict) tolower(s) else s}, 
     sep = "", collapse = " ") 
    sapply(strsplit(s, split = " "), 
     cap, USE.NAMES = !is.null(names(s))) 
} 
# --------------------------------------- 


full<-mutate(geocodes, name=fnames) %>% 
    mutate(category=ifelse(grepl("Winery", name), 1, 2)) %>% 
    mutate(addressUse=gsub("Ny", "NY", capwords(gsub(", usa", "", address)))) %>% 
    mutate(street=sapply(strsplit(addressUse, ","), "[[", 1)) %>% 
    mutate(city=sapply(strsplit(addressUse, ","), "[[", 2)) %>% 
    filter(!grepl('Interlaken|Ithaca|Aurora|Seneca Falls', street)) %>% 
    select(name, street, city, category, lat, lon) 

head(full) 

This article by Jim Plantethis one also by John Harrisonは価値がある:それはページ

# 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() 

の「スニークプレビュー」と(その後にマッピングされている)データを抽出するための機能として、このコードとして次のコードをポストまた見てください。

+0

これは役に立ちません。 Webページにホットキー(apple + a)を送信して、すべてのテキストをハイライト表示できるようにしたい。 – ghostrecon27

+0

@ ghostrecon27 Jim Planteの記事をもう一度読んでください(そして、あなたは明らかに、要素へイベントを送信することを要約したJohn Harrisonの記事を読んでいません)。 –

+0

あなたもどちらも私の質問に答えることができません。ハンマーのようにスクリューには、問題解決能力が足りません。 – ghostrecon27

1

レイチェルが指摘したように、彼女が与えたいくつかのリンクで概説されているキープレスを使うことができます。要素(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() 

コマンドキーは「\ ue03d」のUnicode値を持っています。 RSeleniumで特殊キーに対してこれをチェック:

sapply(selKeys, function(x) identical(x, '\ue03d')) 

は、コマンドキーはMACでとてもcommand_meta(未テスト)として参照されていることを示しますが使用できます。上記で

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

を。

+0

あなたはblogspotのJohn Harrisonですか? Excellent ... :) –

+0

もう一度私が探しているものではありません。誰かがブラウザを開いてウェブサイトに行き、単にcommand + aを押すと想像してください。私はCSSの要素を掻き集めたくない。それは単に私が達成しようとしていることのためにはうまくいかない。 – ghostrecon27

+0

これは、単に "ウェブサイト"に行き、セレンを使ってコマンド+ aを押す方法です。あなたはcss要素を「削る」ことはありません。 – jdharrison

関連する問題