Skip to main content


Webscraping Json Data using Python (Using IP Address)

This is a simple demo which you can use to get IP Address Info using python.



First save IP address in a text file. See the video to understand.
Here is the code:-


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
##JSON URL:- 
json_url = "http://ip-api.com/json/"

import urllib.request as r
import json

file = open("IP_Address.txt","r")

for f in file:
       response = r.urlopen(json_url+str(f))
       data = json.loads(response.read().decode(response.info().get_param('charset') or 'utf-8'))
       for i in data:
             print(str(i)+" = \u3018 "+str(data[i])+" \u3019 ")
       print("---------------------")


For getting specific data use this code:-


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
##JSON URL:- 
json_url = "http://ip-api.com/json/"

import urllib.request as r
import json

file = open("IP_Address.txt","r")

for f in file:
       response = r.urlopen(json_url+str(f))
       data = json.loads(response.read().decode(response.info().get_param('charset') or 'utf-8'))
       print(str("IP Address")+" = \u3018 "+str(data["query"])+" \u3019 ")
       print(str("country")+" = \u3018 "+str(data["country"])+" \u3019 ")
       print(str("zip")+" = \u3018 "+str(data["zip"])+" \u3019 ")
       print("---------------------")

Hope you like the tutorial.

Python is simple and fun to play with and yet very powerful. 🔥


🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍

Popular Posts

Python underline string, Python underline text, Underline python print

Python pip - Installing modules from IDLE (Pyton GUI) for python 3.7

Top 40 Python - String Processing in Python | Working with String in Python

Python Program - When was I born? / Date of Birth / MY BIRTHDAY (using Python3+)

Top 11 Essential Python Tips and Tricks





Subscribe to our Channel


Follow us on Facebook Page

Join our python facebook groups



Join us on Telegram