-
Notifications
You must be signed in to change notification settings - Fork 0
/
route_mairie.rb
28 lines (23 loc) · 905 Bytes
/
route_mairie.rb
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
require 'nokogiri'
require 'open-uri'
def get_the_email_of_a_townhal_from_its_webpage(url)
doc = Nokogiri::HTML(open("http://annuaire-des-mairies.com#{url}"))
doc.css('td')[7].text
end
p get_the_email_of_a_townhal_from_its_webpage('./95/vaureal.html')
def get_all_the_urls_of_val_doise_townhalls
doc = Nokogiri::HTML(open("http://annuaire-des-mairies.com/val-d-oise.html"))
tab = doc.css('p > a').map { |link| link['href'] }
end
def get_all_the_email_of_val_doise_townhalls
res = []
doc = Nokogiri::HTML(open("http://annuaire-des-mairies.com/val-d-oise.html"))
names = doc.css('p > a').map{ |name| name.text }
emails = get_all_the_urls_of_val_doise_townhalls.map{ |url| get_the_email_of_a_townhal_from_its_webpage(url) }
names.length.times do |i|
res += [{ "name" => names[i] , "email" => emails[i] }]
i += 1
end
return res
end
p get_all_the_email_of_val_doise_townhalls