How to Look up a URL's PageRank with Ruby + Open PageRank's API

DomCom’s Open PageRank is a free alternative to Google’s PageRank and includes a public API. All you gotta do before you can use it is fill out this form and they’ll email you an access key.

The limits are generous:

Based on our current limits you can get the PageRank data for 4.3 million domains every single day for a single API Key. If you need more data simply contact us and we will increase the limit.

4.3 million… yeah, that should about cover it.

Using it

The example in their API docs is written in PHP. I’ve translated it here into Ruby, took a bit of fiddling.

require 'net/http'
require 'active_support/all'

uri = URI.parse("https://openpagerank.com/api/v1.0/getPageRank")
uri.query = ["rs.io", "example.com"].to_query('domains')

req = Net::HTTP::Get.new(uri)
req['API-OPR'] = YOUR_SECRET_KEY

res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http|
  http.request(req)
}

result = JSON.parse(res.body)
puts JSON.pretty_generate(result)

Swap YOUR_SECRET_KEY for your actual key and replace the array ["rs.io", "example.com"] with whatever URLs you want to look up, max 100 in a single request like this.

You should get something like,

{
  "status_code": 200,
  "response": [
    {
      "status_code": 200,
      "error": "",
      "page_rank_integer": 4,
      "page_rank_decimal": 4.32,
      "rank": "1443770",
      "domain": "rs.io"
    },
    {
      "status_code": 200,
      "error": "",
      "page_rank_integer": 8,
      "page_rank_decimal": 7.88,
      "rank": "193",
      "domain": "example.com"
    }
  ],
  "last_updated": "16th Aug 2019"
}

The metrics are calculated from Common Crawl’s “open repository of web crawl data that can be accessed and analyzed by anyone”–very cool!

You've read this far⁠—want more?

Subscribe and I'll e-mail you updates along with the ideas that I don't share anywhere else.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.