šŸ¤–
R for SEO
  • Using R for SEO, What to expect?
  • Getting started
  • What is R? What is SEO?
  • About this Book
  • Crawl and extract data
    • What's crawling and why is it useful?
    • Download and check XML sitemaps using R'
    • Crawling with rvest
    • Website Crawling and SEO extraction with Rcrawler
    • Perform automatic browser tests with RSelenium
  • Grabbing data from APIs
    • Grab Google Suggest Search Queries using R'
    • Grab Google Analytics Data x
    • Grab keywords search volume from DataForSeo API using R'
    • Grab Google Rankings from VALUE SERP API using R'
    • Classify SEO Keywords using GPT-3 & R'
    • Grab Google Search Console Data x
    • Grab 'ahrefs' API data x
    • Grab Google Custom search API Data x
    • Send requests to the Google Indexing API using googleAuthR
    • other APIs x
  • Export and read Data
    • Send and read SEO data to Excel/CSV
    • Send your data by email using gmail API
    • Send and read SEO data to Google Sheet x
  • data wrangling & analysis
    • Join Crawl data with Google Analytics Data
    • Count words, n-grams, shingles x
    • Hunt down keyword cannibalization
    • Duplicate content analysis x
    • Compute ā€˜Internal Page Rank’
    • SEO traffic Forecast x
    • URLs categorization
    • Track SEO active pages percentage over time x
  • Data Viz
    • Why Data visualisation is important? x
    • Use Esquisse to create plots quickly
  • Explore data with rPivotTable
  • Resources
    • Launch an R script using github actions
    • Types / Class & packages x
    • SEO & R People x
    • Execute R code online
    • useful SEO XPath's & CSS selectors X
Powered by GitBook
On this page
  • What is VALUE SERP?
  • How to use its API?
  • API Authentication

Was this helpful?

  1. Grabbing data from APIs

Grab Google Rankings from VALUE SERP API using R'

PreviousGrab keywords search volume from DataForSeo API using R'NextClassify SEO Keywords using GPT-3 & R'

Last updated 3 years ago

Was this helpful?

What is VALUE SERP?

It's a great paid API that provides ranking data for a cheap price.

How to use its API?

When you create your account, you are given a few dollars to test the service.

API Authentication

Grab your API key from your

Here is how you can send query, replace the api_key with your own below.

# Loading the right libraries
library(httr)
library(jsonlite)

# Parameters list
params = list(
      `api_key` = 'XXXXXX',
      `q` = "covid",
      `gl` = "fr",
      `hl` = "fr",
      `num` = 20,
      `google_domain` = 'google.fr'
)
# q : the search query
# gl : 2 letter country code 
# hl : language code
# num : number of result asked

# ask for the data
res <- httr::GET(url = 'https://api.valueserp.com/search', query = params)

# translate to string
res_text <- httr::content(res, "text")

# translate to a more readable format
res_json <- jsonlite::fromJSON(res_text, flatten = TRUE)

You can inspect the result by running this command line

View(res_json)

To make it easier for you, I have created a function that you can copy and paste, just replace the api_key with your own below.

serpValueRank <- function(myKwd, glang, hlang, nbr, tld){
  library(httr)
  library(jsonlite)
  all_full_txt <- data.frame(matrix(ncol = 2, nrow = 0))
  colnames(all_full_txt) <- c("kwd", "POS1")
  for (i in 1:length(myKwd)) {
    params = list(
      `api_key` = 'XXXXXX',
      `q` = myKwd[i],
      `gl` = glang,
      `hl` = hlang,
      `num` = nbr,
      `google_domain` = paste0('google', tld)
    )
    message(i, " ", myKwd[i])
    all_full_txt[i, "kwd"] <- myKwd[i]
    res <- httr::GET(url = 'https://api.valueserp.com/search', query = params)
    res_text <- httr::content(res, "text")
    res_json <- jsonlite::fromJSON(res_text, flatten = TRUE)
    for (rslt in 1:length(res_json[["organic_results"]][["link"]])) {
      all_full_txt[i, paste0("POS", rslt)] <-
      res_json[["organic_results"]][["link"]][[rslt]]
    }
  }
  return(all_full_txt)
}

after this has been copy-pasted, you can just launch the function as many times as you want. you can ask for one ranking

ranking <- serpValueRank("covid", "fr", "fr", 20, ".fr")
View(ranking)

or several at once


kwds <- c("covid", "covid test", "covid booster")

kwdsRankings <- serpValueRank(kwds, "fr", "fr", 20, ".fr")

View(kwdsRankings)

āš ļø By default, VALUE SERP will separate all SERP features. Meaning 'organic result' will exclude the video carousel for example. If you would like all of them flattened into the organic_results array, then you could use ā€œflatten_results=trueā€. The flattened ā€œpositionā€ property will include every SERP features

You can also save those results

as a CSV or an Excel file
>> Create an account <<
profile
āš ļø Developer credentials (such as passwords, keys and client IDs) should be kept confidential. āš ļø