Created
February 5, 2019 21:25
-
-
Save voltek62/9c6b07038934f19a7b7dd71f2789a772 to your computer and use it in GitHub Desktop.
Extracting Google Suggest Keyword
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#autoinstall packages | |
packages <- c("XML", "httr") | |
if (length(setdiff(packages, rownames(installed.packages()))) > 0) { | |
install.packages(setdiff(packages, rownames(installed.packages()))) | |
} | |
# Enjoy learning ? https://dataseolabs.com | |
library(httr) | |
library(XML) | |
# put your query | |
query <- URLencode("comment devenir") | |
url <- paste0("http://suggestqueries.google.com/complete/search?output=toolbar&hl=en&q=",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 | |
print(list) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment