-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrape_to_json.py
More file actions
37 lines (32 loc) · 855 Bytes
/
Copy pathscrape_to_json.py
File metadata and controls
37 lines (32 loc) · 855 Bytes
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
import json
import requests
from BeautifulSoup import BeautifulSoup
url = 'http://www.showmeboone.com/sheriff/JailResidents/JailResidents.asp'
response = requests.get(url)
html = response.content
soup = BeautifulSoup(html)
table = soup.find('table', attrs={'class': 'resultsTable'})
list_of_rows = []
for row in table.findAll('tr')[1:]:
list_of_cells = []
for cell in row.findAll('td'):
text = cell.text.replace(' ', '')
list_of_cells.append(text)
list_of_rows.append(list_of_cells)
inmates = []
for row in list_of_rows:
inmate = {
"last": row[0],
"first": row[1],
"middle": row[2],
"gender": row[3],
"race": row[4],
"age": row[5],
"city": row[6],
"state": row[7]
}
inmates.append(inmate)
file = open("./inmates.json", "wb")
output = inmates
json.dump(output, file, indent=2)
file.close()