-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeo_location.py
More file actions
23 lines (23 loc) · 797 Bytes
/
Geo_location.py
File metadata and controls
23 lines (23 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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())