python - Possible to get alexa information or google page rankings over time? -
i trying access historical google page rankings or alexa rankings on time add weightings on search engine making fun. separate function call in python (ideally) , pass in paramaters of url , how long wanted average over, measured in days , use information weight results!
i think fun work on, feel may easy trick of apis guru might able show me , save me few sleepless weeks! can help?
thanks lot !
if @ alexa page stack overflow can see next global rank offers change of site's rank on past 3 months. may not down level of granularity like, scrape out information relatively , doubt gain additional information looking @ changes of different lengths of time. long term answer collect , store rankings have historical record going forward.
update: here sample code.
import mechanize import cookielib beautifulsoup import beautifulsoup def changerankscrapper(site): """ takes site url, scrapes site's alexa page, , returns site's global alexa rank , change in rank on past 3 months. """ #create alexa url url = "http://www.alexa.com/siteinfo/" + site #get html cj = cookielib.cookiejar() mech = mechanize.openerfactory().build_opener(mechanize.httpcookieprocessor(cj)) request = mechanize.request(url) response = mech.open(request) html = response.read() #parse html beautifulsoup soup = beautifulsoup(html) globalrank = int(soup.find("strong", { "class" : "metricsurl font-big2 valign" }).text) changerank = int(soup.find("span", { "class" : "change-wrapper change-up" }).text) return globalrank, changerank #example site = "http://stackoverflow.com/" globalrank, changerank = changerankscrapper(site) print(globalrank) print(changerank)
Comments
Post a Comment