I'd like to download data pertaining to keywords straight into/from R. I understand that RCurl would most probably be the way to go, but I am not sure how to proceed with the task. Perhaps anybody here could put me on the right track?
PS. I may slightly edit this question as answers pour in because I have some ideas of how I could possibly download Adwords data using R; however, the ideas are unclear, and any answers would probably make them clearer.
Many thanks.
EDIT: My attempt
The following is what I tried until now.
1. apply getURL
on the login URL to identify the ids
of the Email and Password fields
require(RCurl)
loginURL<- "https://accounts.google.com/ServiceLogin?service=adwords"
ch<- getCurlHandle()
curlSetOpt(curl=ch,ssl.verifypeer=FALSE,cainfo=system.file("CurlSSL", "cacert.pem", package = "RCurl"),cookiejar="./cookies.txt",cookiefile="./cookies.txt",verbose=TRUE,header=TRUE,followlocation=TRUE,autoreferer=TRUE)
try1<- getURL(loginURL,curl=ch)
2. I identified what the ids
for the important fields (email & password) were
<div class="email-div">
<label for="Email"><strong class="email-label">Email</strong></label>
<input type="email" spellcheck="false"
name="Email" id="Email" value=""
>
</div>
<div class="passwd-div">
<label for="Passwd"><strong class="passwd-label">Password</strong></label>
<input type="password" name="Passwd" id="Passwd"
3. I then used the above fields to apply the postForm
function at the loginURL
in order to log into Google Adwords
params<- list(
"Email"="myemail",
"Passwd"="mypassword",
"GALX"="3b6rR7Jvk30")
loggedIn<- postForm(loginURL,.params=params,curl=ch)
However, I have no idea how to verify that I have successfully logged in.
Plus, the URL for Kyeword planner tool in Google Adwords UI is:
https://adwords.google.com/ko/KeywordPlanner/Home?__c=XXXXXXXXXX&__u=XXXXXXXXXX&__o=cues
where the c= reflects the customer id
and the u= reflects the user id
. What I thought about doing, given this, was to log in using my browser, paste the URL shown above into R, and then try to find out the ids for fields that I will be of relevance to me, such as the id for the keywords text box
in the Keyword planner tool, to which I could possibly send keywords from R.
But when I try to apply getURL
on the aforesaid website, I do not get the required/expected xml tags
or key value pairs
. Instead:
<html><head><noscript><meta http-equiv="refresh" content="0; URL=https://adwords.google.com/select/interstitial_short_js.html"></noscript></head><body><script type="text/javascript" language="javascript">var jsRedirect = true;var url = "/um/StartNewLogin?dst=/ko/KeywordPlanner/Home?__c%3D7857647860%26__u%3D4575929980%26__o%3Dcues";
if (self.document.location.hash) {url = url + ((url.indexOf('?') == -1)? '?' : '&') + "frag=" + self.document.location.hash.substring(1); }
window.location.assign(url);
</script> </body> </html>
This leads me to think that I am probably dealing with Javascript
or AJAX
here.
So, how to extract data from Javascript
or AJAX
using RCurl
, and is this the correct question to ask?
Thanks & apologies for the lengthy edit.