import requests
import re
sites= [("url","sitename"),
("url","sitename"),
("url","sitename")
]
regex = re.compile(r".*POPULARITY URL=.+ TEXT=\"(\d+)\" SOURCE.*")
ranked = []
nonranked = []
def get_rank(site):
s = requests.get("http://data.alexa.com/data?cli=100&url=" + site)
ma = regex.search(s.text)
if ma:
return int(ma.group(1))
return None
# Go through all the sites
for site in sites:
rank = get_rank(site[0])
if rank is not None:
ranked.append((site[0], site[1], rank))
else:
nonranked.append((site[0], site[1], rank))