forked from AllenDowney/ThinkPython
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathzip_code.py
More file actions
34 lines (24 loc) · 728 Bytes
/
zip_code.py
File metadata and controls
34 lines (24 loc) · 728 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
"""This module contains code from
Think Python by Allen B. Downey
http://thinkpython.com
Copyright 2012 Allen B. Downey
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html
"""
"""This is the simplest solution to the problem; I made no effort
to parse the HTML code. Instead I just search for some key words.
An alternative would be to use the HTMLParser module:
http://docs.python.org/library/htmlparser.html
"""
import urllib
zipcode = '02492'
url = 'http://uszip.com/zip/' + zipcode
conn = urllib.urlopen(url)
for line in conn.fp:
line = line.strip()
if 'Population' in line:
print line
if 'Longitude' in line:
print line
if 'Latitude' in line:
print line
conn.close()