How to get Alexa Rank of a site using Python | What is Alexa Ranking | How to use Alexa Rank Checker

Get 300 checks per monthabsolutely FREE!

No credit card needed. No strings attached.

In this video, I have explained:

1. What is Alexa Ranking

2. Who uses Alexa Ranking and

3. How to get Alexa ranking of a website using python programming.

What is Alexa ranking?
[Music] hi friends sanji here again so today i will talk on how to get the alexa rank for any website using python so the first question comes to everyone's mind is what is alexa ranking well it's a website which shows the global and country rank for any website you can find the similar other websites and you can also see what are all the performing keywords on which you can work to get more traffic to your website it also shows how it performed in last 90 days and it updates the rank almost every day now your second question can be who in this universe uses this alexa ranking web administrators to get all the overall performance of the website rank wise bloggers to compare with other blogging competitors sponsors to find the popular sites for sponsored websites or doing the sponsored advertisements itasy folks as it helps in their seo analysis apart from moz rank like page authority rank and domain authority rank commonly known as pa and da rank so now let's get little details about alexa ranking in my browser well i am in the browser and i have opened site info and i am typing the domain name here to get the competitive analysis about this website so let's check uh the global rank country rank and other things for this sanjeev as as it looks like it is very new website so you can just see the global rank you cannot see anything else like as i said audience overlap top keywords and audience geography anything you are not getting lots of details right now let's get back to some other websites which is popular so i have opened again for which you can see the top keywords is their audience who all our audience overlap and you can see the audience geography like from where most of the guys are coming
Global rank and country rank.
now i'm more interested towards the global rank and the country rank so for me these two are of utmost importance but i'm just showing you what all things you can do with this website so when i will do web scrapping to get these two ranks using my python script similar way you can even try for this site matrix audience overlap and there are many improvements that you can do for your seo analysis using this alexa website so the similar way so the similar way now uh there is a website where you can see global rank is being shown here as well and it is being shown here as well well in flex mind uh it was not there right it was only showing here so this is a pattern right when you are going to write a program before that you need to figure out uh what you are going to scrap from this website what all the data that you need to extract from this website and if you are going to extract the data let's say from here possibly for some websites it won't break and your program may crash right so we need to get a proper details from from the website what you are going to extract so now i got that okay this is also showing the global rank but i am more interested towards this particular thing now uh it is showing the global rank and the country rank here as in india this ranks this one now there in a free trial version you can see maximum three country reason here and here so we'll see that in you can see here it is showing these three and then it's showing like okay you need to upgrade to get more details similar for this you need to get a paid version to get more country details for our purpose even this free website and this free version is enough so now uh we want to extract this in our code so before extracting you need to figure out what you are going to extract so i will inspect it and here it is showing that class is big data so now just search for is there anything for big data it is showing there are one of two things are there for big data of course it is also there which i don't want so this is not looking the perfect thing okay or maybe uh you can just extract those two big data and you just get the first one and ignore this second one what could be the other way let's see this rank global is it something which is unique here because the more uniqueness you will have the less regular expression you have to write okay so one of them so what i will do is i will extract the text of this rank global class so it will have all these details right so if you click on this so you can see these all details will be there with this rank global now that's fine i want to get the country rank again now you see uh rank global when you write wrong rank global you are getting one now here in drop down it is showing me three things so again i will inspect this element and i will go little top and i am again seeing here there is showing a country rank so i will just copy paste and will see three are there and fourth one is for this one which i need to ignore because if i uh just try to get this rank i will miss like for which country it is so i cannot just choose this country rank and main tablet from here so i have to choose this class country rank not the class country rank with mean tablet so just you need to be aware about these things when you are scrapping from the website well i personally don't want to open the website to check the alexa rank for one or more websites rather i would like to use my python script to do that
Lets use Python!
for me so let's use python well what you need before making this code to work in your environment uh surely you need python 3 and pip should be working as well and then there are few modules that you need to install like requests and beautiful su4 okay so let's walk through the python code to get the alexa global and country rank for any website well i'm in terminal and here is the code i'm just making the font a little bigger so that it should be visible to all of you i think it should be fine so now you see uh as i have installed required libraries so i'm importing requests library uh this is required to get the content from any website import sys just to get like some command line arguments and then you need beautiful soup for version uh which is commonly referred as bs4 and i'm i'm importing the beautiful soap method from there import re which will be used for regular expression and it is inbuilt like when you install python it will be there now this is uh one of the optional library that you can install i have installed because i need to do some modification in my code and i have taken care of all the edge cases so that it should work for every cases either the website having rank or not that website exists or not right if that website is uh improperly uh validated or not so all these things are there like this base this model basically checks if your website is in a proper uh format or not so now uh this line is this line is optional as i'm making my code fully working and i will also share this code uh through github i will share this code i will share this code link in description so this is just to check like if you are passing the website name in a command line or not if you are not passing it will show you this error okay so now uh this is a base url as you would need to get website rank and whatever the site name you have passed i'm just collecting it here using sys dot rb1 and then i'm lowering it down these are just some more uh modification and making my code readable now i have written a function just to check like if the website that you are passing is a valid or not and i will call this function and if this code is valid it is fine if it is not then it will return false so you can see in this if code i am checking is valid domain with that site name that you passed so if it is not then it will tell you not a valid domain format so these again these all are optional you can you can just remove these things these things and possibly when you don't want to pass through command line argument you just pass the website name so these all lines you can remove so that you your code will be a little smaller but i'm uh i have made this code fully working for all the cases that's the reason it is like that and i'm explaining uh line by line so url for rank is again alexa base url which was site info and the site name that you pass through command line and as i am using this request module i am calling the get method and i will get the page content in this one but this will not be in proper html format so that's the reason you need beautiful soup and inside that i'm writing whatever the page content is there parse it as a html and now this soup will have html content of your website as you saw i was showing you using inspect element so it will be exactly like that and then uh to get the country rank what i'm saying is soup dot find all again it's a method on the div tag check for the country rank and for global rank it is like sub dot select and there was a class called rank hyphen global so whenever there is a class you can call dot and as it was unique so i'm just passing like this otherwise i have to write div class all this right so i'm i'm just making this try catch in case my regular expression doesn't have anything it will tell you like no global rank found for this website so what this regular expression is doing is once you uh got this global rank which will have a list of all these texts so i am just writing like whatever is there in global rank the first match whatever the text is there strip all these things and match if there is any slash d or it can have comma so and it can have uh more ranks like it can be like 7 lakhs or even 70 lakhs or it can be just single digit or anything so it should have a comma or single digit or even more so this plus symbol is for that well don't worry about this regular expression because uh for um i can explain you the regular expression in other video if you guys want to know more about regular expression so please comment in the video if you want to understand regular expression as well so
Retrieving websiste rank.
the similar thing now i am doing for rank as you saw like rank can be more than one as well so i am getting this as a list and i'm just passing through this for loop and i'm saying like if you uh see this rank get the details from that and now uh with this rank there will be a country also right uh like you have to show the country right so automatically you will see uh whenever you are searching for this the same line will have that country flag so you don't need to worry about that country flag and with that country flag you can easily understand if it is india us any other country right and if it doesn't find anything it will say no country rank was found yeah so this is the code now let's go and run this code so let's say i will run the code alexa dot okay so um it should be python 3 and then i will say alexa rank and uh what i will do is i will not pass any argument let's see what it is say so it says please pass the tld top level domain url without https and you need to pass like python alexa rank the script name and the top level domain name for example python alexa rank.pi and the site name so now i will pass alexa rank so i'm passing a website name which doesn't exist and it's not in a proper format so you see uh that import validators this error is coming from that not a valid domain format you need to pass a proper format either with www or without www so now i'm passing flex mind dot something this website doesn't exist right so now this will not be cached by validators but validators only catch if it it looks like a website now it will go through that and as this website doesn't exist so there will be no global rank no country rank so it exactly uh did all these edge cases and uh with this try and exit block this program is not crossing this program is not throwing any error so you are in a proper shape now uh let's do the real thing alexa underscore rank and then i will pass wait for a few seconds and it will give you the global rank and country rank here you go global rank is this one country rank see you can see hash india and this rank well i can do the similar thing for any website which doesn't have country rank like sanjeev so it it has only global rank but it doesn't have the country rank well it catched very well so now the similar way uh let's try for here you go now you see uh it's global rank and country rank it is showing three things united states india saudi arabia exactly we saw the same thing in the website so now you can even um further customize or fine-tune this script and you can uh try to get other details like what are all the top five competitors of your website and what are all the keywords where you can rank so you can do all these data scrapping using beautiful soup and request module and also you just need to figure out what are all the div columns div tags or classes or id which you need to find out and when you have text you need to use regular expression to exactly get what you want so that's all from this code perspective so i hope you enjoyed the video the code walkthrough and the explanation regarding alexa ranking if you like this video and you think like if it is useful for you and for your other friends so please like and subscribe our channel and share this video as well and please let me know how you liked this video through the comment is there anything else that you wanted me to cover and is there any other topic that you want me to cover so all these things you can please write in comment and here is my social profile you can follow me in twitter instagram linkedin or even in youtube

Get 300 checks per month absolutely FREE!

No credit card needed. No strings attached. 👍