Skip to content

Instantly share code, notes, and snippets.

@VioletVivirand
Last active March 29, 2018 04:37
Show Gist options
  • Save VioletVivirand/6fc5a9ceb1a3b1587a210bbb10ec644b to your computer and use it in GitHub Desktop.
Save VioletVivirand/6fc5a9ceb1a3b1587a210bbb10ec644b to your computer and use it in GitHub Desktop.
One-liner Alexa Rank
# Reference:
# https://samelh.com/blog/2017/10/01/get-alexa-site-rank-python-php-javascript/
import requests, re
alexa = 'http://data.alexa.com/data?cli=10&dat=s&url={0}'
search_domain = 'google.com'
r = requests.get(alexa.format(search_domain))
xml = r.text
rank = int(re.search(r'<POPULARITY[^>]*TEXT="(\d+)"', xml).groups()[0])
print('Alexa Rank of {0} = {1}'.format(search_domain, rank))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment