Unable to GET/download data into R from URL; returning HTML instead

16 Views Asked by At

This page is an example of a hotspot bar chart from eBird. It visually depicts historical bird occurrence data at a given location over the course of the year. There is a URL at the bottom of the page to download the data. If I click that URL, my browser automatically downloads a .txt file that, when opened, contains a perfectly legible tab-separated table.

I am trying to access and bring that data into R without having to download the .txt manually. But I am running into the following problem: the URL returns an html document.

I have tried the following two approaches to pull in the data, both of which return the same content. I should add the the html document does not have the numeric values that I need, so scraping this isn't a workaround in this case.

url = "https://ebird.org/barchartData?r=L6334917&bmo=1&emo=12&byr=1900&eyr=2024&fmt=tsv"r
destination = "downloaded_data.tsv"


# 1 
download.file(url, destfile = destination, method = "auto", quiet = FALSE)

# 2
returned <- VERB("GET", url = url)
content <- returned$content
json_string <- rawToChar(content)

print(json_string) 

[1] "\n\n\n<!doctype html>\n\n\n\n\n\n\n<html lang=\"en\" class=\"no-js\"><!--<![endif]--> ...
 

Is there a way I can make R behave the way my browser behaves and return the same tab-separated .txt file?

0

There are 0 best solutions below