Hello, I am trying to use R to download a bunch of .csv files such as: http://biocache.ala.org.au/ws/occurrences/download?q=Banksia+ericifolia I have tried the following and neither work: a<- getURL(" http://biocache.ala.org.au/ws/occurrences/download?q=Banksia+ericifolia") Error in curlPerform(curl = curl, .opts = opts, .encoding = .encoding) : embedded nul in string: and a<-httpPOST(" http://biocache.ala.org.au/ws/occurrences/download?q=Banksia+ericifolia") Error: Internal Server Error Any help would be appreciated. Daisy -- Daisy Englert Duursma Department of Biological Sciences Room E8C156 Macquarie University, North Ryde, NSW 2109 Australia [[alternative HTML version deleted]]
Hi Daisy Use getURLContent() rather than getURL(). The former handles binary content and this appears to be a zip file. You can write it to a file or read its contents directly in memory, e.g library(RCurl) z = getURLContent("http://biocache.ala.org.au/ws/occurrences/download?q=Banksia+ericifolia") attributes(z) library(Rcompression) ar = zipArchive(z) names(ar) getZipInfo(ar) ar[["data.csv"]] dd = read.csv(textConnection(ar[["data.csv"]])) D. On 7/23/13 2:59 AM, Daisy Englert Duursma wrote:> Hello, > I am trying to use R to download a bunch of .csv files such as: > > http://biocache.ala.org.au/ws/occurrences/download?q=Banksia+ericifolia > > I have tried the following and neither work: > > a<- getURL(" > http://biocache.ala.org.au/ws/occurrences/download?q=Banksia+ericifolia") > > Error in curlPerform(curl = curl, .opts = opts, .encoding = .encoding) : > embedded nul in string: > and > > a<-httpPOST(" > http://biocache.ala.org.au/ws/occurrences/download?q=Banksia+ericifolia") > > Error: Internal Server Error > > > Any help would be appreciated. > > Daisy >
On Jul 23, 2013, at 2:59 AM, Daisy Englert Duursma wrote:> Hello, > I am trying to use R to download a bunch of .csv files such as:It's are not a csv file; instead it's a zip file. Why not use the `download.file` function. This downloads it to my working directory:> download.file("http://biocache.ala.org.au/ws/occurrences/download?q=Banksia+ericifolia", "data.zip")trying URL 'http://biocache.ala.org.au/ws/occurrences/download?q=Banksia+ericifolia' Content type 'application/zip' length unknown opened URL .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .... downloaded 204 Kb -- David.> > http://biocache.ala.org.au/ws/occurrences/download?q=Banksia+ericifolia > > I have tried the following and neither work: > > a<- getURL(" > http://biocache.ala.org.au/ws/occurrences/download?q=Banksia+ericifolia") > > Error in curlPerform(curl = curl, .opts = opts, .encoding = .encoding) : > embedded nul in string: > and > > a<-httpPOST(" > http://biocache.ala.org.au/ws/occurrences/download?q=Banksia+ericifolia") > > Error: Internal Server Error > > > Any help would be appreciated. > > Daisy > -- > Daisy Englert Duursma > Department of Biological Sciences > Room E8C156 > Macquarie University, North Ryde, NSW 2109 > Australia > > [[alternative HTML version deleted]]And do learn to post in plain-text. -- David Winsemius Alameda, CA, USA