Last active
March 29, 2018 04:37
-
-
Save VioletVivirand/6fc5a9ceb1a3b1587a210bbb10ec644b to your computer and use it in GitHub Desktop.
One-liner Alexa Rank
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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