R Code Examples
The following are code examples on how to integrate the ScrapeOps Residential Proxy Aggregator with your R Scrapers using httr.
Authorisation - API Key
To use the ScrapeOps proxy, you first need an API key which you can get by signing up for a free account here.
Your API key must be included with every request using the api_key
query parameter otherwise the API will return a 403 Forbidden Access
status code.
Basic Request
The following is some example code to send a URL to the ScrapeOps Proxy port http://scrapeops:YOUR_API_KEY@residential-proxy.scrapeops.io:8181
.
First, you'll need to install the 'httr' package before running this code:
install.packages("httr")
Here is the example code.
library(httr)
api_key <- 'YOUR_API_KEY'
url <- 'https://httpbin.org/ip'
proxy_port <- paste0('http://scrapeops:', api_key, '@residential-proxy.scrapeops.io:8181')
response <- GET(
url = url,
use_proxy(proxy_port),
timeout(120)
)
if (status_code(response) == 200) {
content <- content(response, as = "text")
cat('Body:', content, '\n')
} else {
cat('Error:', status_code(response), '\n')
}
ScrapeOps will take care of the proxy selection and rotation for you so you just need to send us the URL you want to scrape.