-
Notifications
You must be signed in to change notification settings - Fork 36
/
btphone.py
executable file
·38 lines (32 loc) · 1.05 KB
/
btphone.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
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
# Search UK BT Phonebook for residential numbers based on surname and location
# by @catalyst256
import requests
import sys
from BeautifulSoup import BeautifulSoup
def lookup_name(name, location):
details = []
url = 'http://www.thephonebook.bt.com/publisha.content/en/search/residential/search.publisha?Surname=%s&Location=%s&Initial=&Street=' %(name, location)
try:
r = requests.get(url)
html = r.text
parsed_html = BeautifulSoup(html)
x = parsed_html.body.findAll('div', attrs={'class':'recordBody'})
if len(x) == 0:
pass
else:
for s in x:
details.append(s.text.replace('Tel: (', ',').replace(')', '').replace('-Text Number', ',').replace('-Map', '').split(','))
return details
except Exception as e:
return e
if __name__ == '__main__':
if len(sys.argv) != 3:
print 'Usage: ./btphone.py [Surname] [Location]'
print 'Example: ./btphone.py Bloggs London'
sys.exit(1)
name = sys.argv[1]
location = sys.argv[2]
x = lookup_name(name, location)
for i in x:
print i