0

I am trying to open a url in a browser in MAC attempting to save a file. For example, the following link when opened in a browser will download a cvs file from google trends. However if I use the function browseURL, it does not open anything or saves anything.

 URL="http://www.google.com/trends/trendsReport?hl=en-US&q=FTSE 100&date=1%2F2015 1m&cmpt=q&content=1&export=1"
  browseURL(URL)  

it works for webpages like (it open the page on the browser) URL="http://www.google.com" browseURL(URL)

but it doesn't work when it is the csv file of google trends. I tried to replicate the example shown here: http://www.quora.com/What-is-the-way-to-bulk-download-a-CSV-file-from-Google-Trends

Any ideas?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
ruthy_gg
  • 337
  • 3
  • 11
  • Also, I would really appreciate if someone could tell me how many download google trends allows before blocking the IP. How long should I wait to try again? Thanks – ruthy_gg Jun 26 '15 at 19:30
  • Your URL is not a viewable page, it is a direct link to a cvs file. – SabDeM Jun 26 '15 at 19:31
  • My intention is to imitate the behaviour of coping and pasting "that" url so that I can "save" the csv file locally. If browseURL can not do this, What would be the alternative then? Any idea? I tried file.download and it does not work, it saves other thing. – ruthy_gg Jun 26 '15 at 19:38

1 Answers1

0

Ok found a way! For a reason I could not replicate the code exactly as the Quora post. The reason was in the encoding of the url in my Mac. Maybe it worked for the author who seemed to use Windows but it did not work in my Mac.

It was solved by altering the code in the following way:

# Dates
if(!is.na(year)){
  date <- paste0("&date=", month, "%2F", year, "%20", length, "m")
}

and then

trendsDir <- vector()
for (i in year){
  for (j in 1:12){
    URL <- URL_GT(keyword = seach_word, year = i, month = j, length = 1)
    URL <- gsub(" ", "%20", URL, fixed = TRUE)
  }
}

The URL <- gsub(" ", "%20", URL, fixed = TRUE) made the difference for me.

Kim
  • 4,080
  • 2
  • 30
  • 51
ruthy_gg
  • 337
  • 3
  • 11