Created
July 24, 2012 16:02
-
-
Save masnun/3170870 to your computer and use it in GitHub Desktop.
Python One-liner to get your site's Alexa Rank
This file contains hidden or 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
#!/usr/bin/env python | |
import urllib, sys, bs4 | |
print bs4.BeautifulSoup(urllib.urlopen("http://data.alexa.com/data?cli=10&dat=s&url="+ sys.argv[1]).read(), "xml").find("REACH")['RANK'] |
:) @risheek20
import urllib.request, sys, re
import xmltodict, json
xml = urllib.request.urlopen('http://data.alexa.com/data?cli=10&dat=s&url={}'.format("www.example.com")).read()
result= xmltodict.parse(xml)
data = json.dumps(result).replace("@","")
data_tojson = json.loads(data)
url = data_tojson["ALEXA"]["SD"][1]["POPULARITY"]["URL"]
rank= data_tojson["ALEXA"]["SD"][1]["POPULARITY"]["TEXT"]
print("site {site}, rank {rank}".format(site=url,rank=rank))
I made one here: alexa_check.py
Not a one liner but it gets all ranks available, global and national. It will also show other countries rank (sometimes only one country will be shown on the website-besides global)...
For instance facebook.com will show only Global and US rank on the Alexa page. However my script finds that they are number 1 in several countries
:) @risheek20
import urllib.request, sys, re import xmltodict, json xml = urllib.request.urlopen('http://data.alexa.com/data?cli=10&dat=s&url={}'.format("www.example.com")).read() result= xmltodict.parse(xml) data = json.dumps(result).replace("@","") data_tojson = json.loads(data) url = data_tojson["ALEXA"]["SD"][1]["POPULARITY"]["URL"] rank= data_tojson["ALEXA"]["SD"][1]["POPULARITY"]["TEXT"] print("site {site}, rank {rank}".format(site=url,rank=rank))
hey buddy, ther's problem with parser.Parse(xml_input, True) ..... can you please edited???
I would rate it very much
Thanks in advance!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
error is popping that index is out of bound...help!!!