Google使用R推动数据自动化

时间:2018-07-27 05:53:29

标签: r rselenium google-trends

我一直在尝试使用以下代码自动化下载过程:

{`devtools::install_github("ropensci/RSelenium")
library(RSelenium)
library(devtools)
library(curl)
RSelenium::checkForServer()
RSelenium::rsDriver
selXML <- xmlParse(paste0(selURL, "/?delimiter="))
checkForServer()
startServer()
file.path(find.package("RSelenium"), "examples/serverUtils")
rD <- rsDriver(port=4444L,browser="chrome")
remDr <- remoteDriver$new()
remDr$open
remDr <- rD$client
remDr$navigate("https://trends.google.com/trends/")
WebElem1 <- remDr$findElement( using = = 'xpath', vaue='//* 
[@id="input256"]') 

WebElem1$sendKeysToElement(list('R', key = 'enter'))

 WebElem2 <- remDr$findElement(using = 'xpath', value = 
'/html/body/div[2]/div[2]/div/md-content/div/div/div[1]/trends-widget/ng- 
include/widget/div/div/div/widget-actions/div/button[1]')
WebElem2$clickElement() `}

运行此命令后,将打开网页,但未输入值。我已经使用了Google趋势数据文本框的xpath。下载正常。

0 个答案:

没有答案