Skip to content

Latest commit

 

History

History
50 lines (26 loc) · 1.15 KB

File metadata and controls

50 lines (26 loc) · 1.15 KB

Find_Geo_Location_By_Python

we find the Geo Location with help of this script. In this script scrape data from https://ipinfodb.com/ site. this article only for education purpose not for any illegal purpose.

Code:-

import requests

from bs4 import BeautifulSoup

def Geo_Location(): page=requests.get("https://ipinfodb.com/").text

soup=BeautifulSoup(page,'html.parser')

data=soup.find('table',{'class':'table'})

result=[]

for rows in data.find_all('tr'):

    cols=rows.find_all('td')
    
    if len(cols)>=2:
    
        try: 
        
            result.append([cols[0].text,cols[1].text,cols[2].text])
            
        except:
        
            result.append([cols[0].text,cols[1].text])
            
address={}

ip=soup.find('h1',{'class':'pull-left'}).strong.text.split('-')

address[ip[0].strip()]=ip[1].strip()

for k in range(len(result)):

    for i in result[k]:
    
        address[i.split('\n')[1]]=i.split('\n')[2]
        
return address

if name == "main":

print(Geo_Location())