Python 3 Pycurl Library Script to Find Website Alexa Global and Country Rank Using Alexa API and BeautifulSoup4 Library Full Project For Beginners

Python 3 Pycurl Library Script to Find Website Alexa Global and Country Rank Using Alexa API and BeautifulSoup4 Library Full Project For Beginners

 

Welcome folks today in this blog post we will be building a alexa rank checker app using beautifulsoup4 library and alexa api in python. All the source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to install the following library using the pip command as shown below

 

pip install pycurl

 

pip install bs4

 

After installing this library you need to make an app.py file and copy paste the following code

 

app.py

 

#! /usr/bin/python
import sys
import pycurl
from bs4 import BeautifulSoup
try:
    # python 3
    from urllib.parse import urlencode
except ImportError:
    # python 2
    from urllib import urlencode
try:
    from io import BytesIO
except ImportError:
    from StringIO import StringIO as BytesIO

def banner():
    '''
    ````
    Github Profile : https://github.com/hexageek1337
    Github Project : https://github.com/hexageek1337/Checker-Alexa-Rank ( 17-05-2018 )
    Created by Denny Septian
    
    ````
    '''

banner()
URLWEB = raw_input("| Input url your site (example : github.com) : ")
buffer = BytesIO()
c = pycurl.Curl()
c.setopt(c.URL, "http://data.alexa.com/data?cli=10&dat=snbamz&url="+URLWEB)
c.setopt(c.WRITEDATA, buffer)
c.perform()

# HTTP response code, e.g. 200.
print("----------------------------------------")
if c.getinfo(c.RESPONSE_CODE) == 200:
    print('| [+] Response Status : %d ( Found )' % c.getinfo(c.RESPONSE_CODE))
else:
    print('| [+] Response Status : %d ( Fail )' % c.getinfo(c.RESPONSE_CODE))
# Elapsed time for the transfer.
print('| [+] Response time : %f' % c.getinfo(c.TOTAL_TIME))
print("----------------------------------------")

# getinfo must be called before close.
c.close()

body = buffer.getvalue()

y = BeautifulSoup(body, "html.parser")
print("| [+] Country : "+y.findAll("country")[0]["name"])
print("| [+] Global Rank : "+y.findAll("popularity")[0]["text"])
print("| [+] Country Rank : "+y.findAll("country")[0]["rank"])
print("----------------------------------------")

 

See also  Python 3 Tkinter Tick Scale Slider Widget Using ttkwidgets Library GUI Desktop App Full Project For Beginners

 

Now if you execute the python script by typing the below command as shown below

 

python app.py codingshiksha.com

 

 

 

So as you can see it has printed out the alexa global rank and country rank

 

Leave a Reply