-
Notifications
You must be signed in to change notification settings - Fork 0
/
zonasRecreativas.py
149 lines (132 loc) · 6.23 KB
/
zonasRecreativas.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- encoding: utf-8 -*-
# encoding: latin1
import re
import sys
import urllib.request
def cargar_links():
expr = "href=\"equipamiento"
wp = urllib.request.urlopen (
"http://www.gobiernodecanarias.org/cmayot/centrodocumentacion/recursoseducativos/guia_equipamientos_naturaleza/guiaequip.jsp?id_isla=40&id_tipo=3" )
pw = wp.read ( ).decode ( wp.headers.get_content_charset ( ) )
res = pw.split ( )
indx = [ ]
res2 = [ ]
for i in range ( 0 , len ( res ) ):
if re.search ( expr , str ( res[ i ] ) ):
indx += [ i ]
res2 = [ ]
for i in range ( 0 , len ( indx ) ):
aux = str ( res[ indx[ i ] ] ).split ( "=\"" )
tam = len ( aux )
#print(aux)
res[ indx[ i ] ] = aux[ tam - 1 ]
aux = str ( res[ indx[ i ] ] ).split ( "\"" )
res[ indx[ i ] ] = aux[ 0 ]
res[ indx[ i ] ] = res[ indx[ i ] ].replace ( "aspx" , "htm" )
res2 += [ "http://www.gobiernodecanarias.org/cmayot/centrodocumentacion/recursoseducativos/guia_equipamientos_naturaleza/" + res[ indx[ i ] ] ]
#print(res2)
print("Done")
return res2
links1 = cargar_links()
resultado = [ ]
for i in range ( 0 , len ( links1 ) ):
vec_ub = urllib.request.urlopen ( links1[ 0 ] )
vec_ub = vec_ub.read ( ).decode ( vec_ub.headers.get_content_charset ( ) )
vec_ub = vec_ub.split ( "<" )
vec_lin = urllib.request.urlopen ( links1[ i ] )
vec_lin = vec_lin.read ( ).decode ( vec_lin.headers.get_content_charset ( ) )
vec_lin = vec_lin.split ( "<strong>" )
for i in range ( 0 , len ( vec_lin ) ):
if re.search ( "Nombre" , str ( vec_lin[ i ] ) ):
aux = vec_lin[ i ].split ( "class=\"fondogris\">" )
aux = aux[ 1 ].split ( "</td>" )
resultado += [ aux[ 0 ].lstrip ( ) ]
for i in range ( 0 , len ( vec_lin ) ):
if re.search ( "Isla" , str ( vec_lin[ i ] ) ):
aux = vec_lin[ i ].split ( "class=\"fondogris\">" )
aux = aux[ 1 ].split ( "</td>" )
resultado += [ aux[ 0 ].lstrip ( ) ]
for i in range ( 0 , len ( vec_lin ) ):
if re.search ( "Municipio" , str ( vec_lin[ i ] ) ):
aux = vec_lin[ i ].split ( "class=\"fondogris\">" )
aux = aux[ 1 ].split ( "</td>" )
resultado += [ aux[ 0 ].lstrip ( ) ]
for i in range ( 0 , len ( vec_lin ) ):
if re.search ( "Acceso " , str ( vec_lin[ i ] ) ):
aux = vec_lin[ i ].split ( "class=\"fondogris\">" )
aux = aux[ 1 ].split ( "</td>" )
resultado += [ aux[ 0 ].lstrip ( ) ]
for i in range ( 0 , len ( vec_lin ) ):
if re.search ( "Transporte" , str ( vec_lin[ i ] ) ):
aux = vec_lin[ i ].split ( "class=\"fondogris\">" )
aux = aux[ 1 ].split ( "</td>" )
resultado += [ aux[ 0 ].lstrip ( ) ]
for i in range ( 0 , len ( vec_lin ) ):
if re.search ( "Contacto:" , str ( vec_lin[ i ] ) ):
aux = vec_lin[ i ].split ( "class=\"fondogris\">" )
aux = aux[ 1 ].split ( "</td>" )
resultado += [ aux[ 0 ].lstrip ( ) ]
for i in range ( 0 , len ( vec_lin ) ):
if re.search ( "Permiso/Autorización:" , str ( vec_lin[ i ] ) ):
aux = vec_lin[ i ].split ( "class=\"fondogris\">" )
aux = aux[ 1 ].split ( "</td>" )
resultado += [ aux[ 0 ].lstrip ( ) ]
for i in range ( 0 , len ( vec_lin ) ):
if re.search ( "Superficie" , str ( vec_lin[ i ] ) ):
aux = vec_lin[ i ].split ( "class=\"fondogris\">" )
aux = aux[ 1 ].split ( "</td>" )
resultado += [ aux[ 0 ].lstrip ( ) ]
for i in range ( 0 , len ( vec_lin ) ):
if re.search ( "Accesibilidad para minusválidos:" , str ( vec_lin[ i ] ) ):
aux = vec_lin[ i ].split ( "class=\"fondogris\">" )
aux = aux[ 1 ].split ( "</td>" )
resultado += [ aux[ 0 ].lstrip ( ) ]
for i in range ( 0 , len ( vec_lin ) ):
if re.search ( "Agua" , str ( vec_lin[ i ] ) ):
aux = vec_lin[ i ].split ( "class=\"fondogris\">" )
aux = aux[ 1 ].split ( "</TD>" )
resultado += [ aux[ 0 ].lstrip ( )]
for i in range ( 0 , len ( vec_lin ) ):
if re.search ( "Electricidad" , str ( vec_lin[ i ] ) ):
aux = vec_lin[ i ].split ( "class=\"fondogris\">" )
aux = aux[ 1 ].split ( "</TD>" )
resultado += [ aux[ 0 ].lstrip ( ) ]
for i in range ( 0 , len ( vec_lin ) ):
if re.search ( "Duchas" , str ( vec_lin[ i ] ) ):
aux = vec_lin[ i ].split ( "class=\"fondogris\">" )
aux = aux[ 1 ].split ( "</TD>" )
resultado += [ aux[ 0 ].lstrip ( ) ]
for i in range ( 0 , len ( vec_lin ) ):
if re.search ( "Bar" , str ( vec_lin[ i ] ) ):
aux = vec_lin[ i+1 ].split ( "class=\"fondogris\">" )
aux = aux[ 1 ].split ( "</TD>" )
resultado += [ aux[ 0 ].lstrip ( ) ]
for i in range ( 0 , len ( vec_lin ) ):
if re.search ( "Comedor" , str ( vec_lin[ i ] ) ):
aux = vec_lin[ i ].split ( "class=\"fondogris\">" )
aux = aux[ 1 ].split ( "</TD>" )
resultado += [ aux[ 0 ].lstrip ( ) ]
for i in range ( 0 , len ( vec_lin ) ):
if re.search ( "Fogones" , str ( vec_lin[ i ] ) ):
aux = vec_lin[ i ].split ( "class=\"fondogris\">" )
aux = aux[ 1 ].split ( "</TD>" )
resultado += [ aux[ 0 ].lstrip ( ) ]
for i in range ( 0 , len ( vec_lin ) ):
if re.search ( "Bancos," , str ( vec_lin[ i ] ) ):
aux = vec_lin[ i ].split ( "class=\"fondogris\">" )
aux = aux[ 1 ].split ( "</TD>" )
resultado += [ aux[ 0 ].lstrip ( ) ]
for i in range ( 0 , len ( vec_lin ) ):
if re.search ( "Aparcamientos" , str ( vec_lin[ i ] ) ):
aux = vec_lin[ i ].split ( "class=\"fondogris\">" )
aux = aux[ 1 ].split ( "</TD>" )
resultado += [ aux[ 0 ].lstrip ( ) ]
print (resultado)
with open ( 'lib/output2.csv' , 'a' ) as f:
print (len ( resultado ))
f.write ( ((str ( resultado )).replace ( "[" , "" )).replace ( "]" , "" ) )
f.write ( "\n" )
f.close ( )
resultado = [ ]