Hi everyone,
Here is my problem :
I would like to scrap Google PAA (people also ask) for several keywords with R.
I've got a problem with my R loop.
It does not take all my keyword in the loop ...
Could you please help me ?
Thank you in advance
Here is my code :
mykeyword <- c("canape","ps4","macbook")
my_user_agent <- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:59.0) Gecko/20100101 Firefox/59.0"
#Lancement
url_to_check <- paste0("https://www.google.com/search?q=",mykeyword[1],"&ie=utf-8&oe=utf-8&client=firefox-b")
PAA <- GET(url_to_check, user_agent(my_user_agent)) %>%
htmlParse(encoding = "UTF-8") %>%
xpathSApply('//div[/*]/g-accordion-expander/div/div', xmlValue)
for (i in 1: length(mykeyword)) {
url_to_check <- paste0("https://www.google.com/search?q=",mykeyword[i],"&ie=utf-8&oe=utf-8&client=firefox-b")
PAA_2 <- GET(url_to_check, user_agent(my_user_agent)) %>%
htmlParse(encoding = "UTF-8") %>%
xpathSApply('//div[/*]/g-accordion-expander/div/div', xmlValue)
df = rbind(PAA,PAA_2)
}