Skip to content

Instantly share code, notes, and snippets.

@elhardoum
Forked from masnun/alexa.py
Last active October 3, 2017 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elhardoum/f9280c73720836e6ea0fa737fe972cbd to your computer and use it in GitHub Desktop.
Save elhardoum/f9280c73720836e6ea0fa737fe972cbd to your computer and use it in GitHub Desktop.

Usage

  • Download alexa.py
wget https://gist.github.com/elhardoum/f9280c73720836e6ea0fa737fe972cbd/raw/9045401cb378be0fa0711e6357ce0efcad15fbae/alexa.py
  • chmod +x alexa.py (optional if you execute with python: python alexa.py <args>)
  • ./alexa.py wikipedia.org
#!/usr/bin/env python
import urllib, sys, re
xml = urllib.urlopen('http://data.alexa.com/data?cli=10&dat=s&url=%s'%sys.argv[1]).read()
try: rank = int(re.search(r'<POPULARITY[^>]*TEXT="(\d+)"', xml).groups()[0])
except: rank = -1
print 'Your rank for %s is %d!\n' % (sys.argv[1], rank)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment