Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Extracting Google Suggest Keyword
#autoinstall packages
packages <- c("XML", "httr")
if (length(setdiff(packages, rownames(installed.packages()))) > 0) {
install.packages(setdiff(packages, rownames(installed.packages())))
# Enjoy learning ?
# put your query
query <- URLencode("comment devenir")
url <- paste0("",query)
# use GET method
req <- GET(url)
# extract xml
xml <- content(req)
# parse xml
doc <- xmlParse(xml)
# extract attributes from
# <CompleteSuggestion><suggestion data="XXXXXX"/></CompleteSuggestion>
list <- xpathSApply(doc, "//CompleteSuggestion/suggestion", xmlGetAttr, 'data')
# print results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.