-
Notifications
You must be signed in to change notification settings - Fork 4
/
phone_lookup.py
28 lines (22 loc) · 913 Bytes
/
phone_lookup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from bs4 import BeautifulSoup as htmlparser
import requests
def lookup(phone_number):
http = requests.get(f"https://free-lookup.net/{phone_number}")
html = htmlparser(http.text, "html.parser")
infos = html.findChild("ul", {"class": "report-summary__list"}).findAll("div")
return {k.text.strip(): infos[i+1].text.strip() if infos[i+1].text.strip() else "No information" for i, k in enumerate(infos) if not i % 2}
def main():
while True:
try:
phone_number = input("Phone number: ").strip().replace("-", "").replace(" ", "").replace("+", "")
except KeyboardInterrupt:
return
try:
infos = lookup(phone_number)
except AttributeError:
print("Error: Invalid phone number\n")
continue
[print(f"{info}: {infos[info]}") for info in infos]
print("\n")
if __name__ == "__main__":
main()