-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscraper.py
61 lines (44 loc) · 1.43 KB
/
scraper.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import scraperwiki
import requests
from BeautifulSoup import BeautifulStoneSoup
"""
bbox is the bounding box for the selected area. The first coordinate pair is the lower left corner and the second upper right
The last element is the Map Feature: http://wiki.openstreetmap.org/wiki/Map_Features#Sustenance
"""
url = "http://www.overpass-api.de/api/xapi?node[bbox=13.000717,52.373922,13.742294,52.707179][amenity=library]"
xml = requests.get(url, verify = False).text
soup = BeautifulStoneSoup(xml)
nodes = soup.findAll('node')
for node in nodes:
id = node['id']
lat = node['lat']
lon = node['lon']
try:
houseNumber= node('tag', k = 'addr:housenumber')[0]['v']
except IndexError:
houseNumber = None
try:
street = node('tag', k = 'addr:street')[0]['v']
except IndexError:
street = None
try:
name = node('tag', k = 'name')[0]['v']
except IndexError:
name = None
try:
website = node('tag', k = 'website')[0]['v']
except IndexError:
website = None
try:
phone = node('tag', k = 'phone')[0]['v']
except IndexError:
phone = None
data = {'id' : id,
'name' : name,
'lat' : lat,
'lon' : lon,
'website' : website,
'street' : street,
'houseNumber' : houseNumber,
'phone': phone}
scraperwiki.sqlite.save(unique_keys=['id'], data=data)