-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path02-salaries-basic.py
More file actions
35 lines (22 loc) · 870 Bytes
/
02-salaries-basic.py
File metadata and controls
35 lines (22 loc) · 870 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
import requests
import csv
from BeautifulSoup import BeautifulSoup
########## STEP 1: Open and read the URL ##########
url = 'http://mapyourtaxes.mo.gov/MAP/Employees/Employee/SearchResults.aspx?last=%25&first=%25&year=2013&agency=931'
response = requests.get(url)
html = response.content
########## STEP 2: Parse HTML with BeautifulSoup ##########
soup = BeautifulSoup(html)
results_table = soup.find('table', attrs={'id': 'grdEmployees'})
########## STEP 3: Iterate through the results and write to an output list ##########
output = []
for row in results_table.findAll('tr'):
output_row = []
for cell in row.findAll('td'):
output_row.append(cell.text)
output.append(output_row)
########## STEP 4: Write results to file ##########
print(output)
handle = open('out-basic.csv', 'a')
outfile = csv.writer(handle)
outfile.writerows(output)