-
Notifications
You must be signed in to change notification settings - Fork 0
/
fun_meteo_scraper_82.py
59 lines (43 loc) · 2.04 KB
/
fun_meteo_scraper_82.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
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 09 10:02:43 2017
@author: d_floriello
functions for meteo web scraper server 82
"""
import pandas as pd
def GetMonth(browser, city, lm, anno):
browser.get('http://www.ilmeteo.it/portale/archivio-meteo')
elem = browser.find_element_by_id('edit-zearch')
elem.send_keys(city)
clicker = browser.find_element_by_name('search_submit')
clicker.click()
browser.find_element_by_xpath("//select[@name='anno']/option[text()=" + str(anno) + "]").click()
elem2 = browser.find_element_by_link_text(lm)
elem2.click()
browser.find_element_by_xpath("//select[@name='anno']/option[text()=" + str(anno) + "]").click()
browser.find_element_by_name("conferma").click()
# '//*[@title="dati storici Milano Settembre 2016"]'
xpath = '//*[@title="dati storici ' + city + ' ' + lm + ' ' + anno +'"]'
elem3 = browser.find_element_by_xpath(xpath)
elem3.click()
print 'done {} in {}'.format(city, lm)
return 1
###############################################################################
def GetListMonth(browser, city, list_month, anno):
for lm in list_month:
GetMonth(browser, city, lm, anno)
return 1
###############################################################################
def ElaborateExcel(city, list_mesi, anno):
df = pd.read_excel('C:/Users/d_floriello/Documents/PUN/'+city+' '+str(anno)+'.xlsx')
dfnames = df.columns
for m in list_mesi:
dfloc = pd.read_csv('C:/Users/d_floriello/Downloads/'+city+'-'+str(anno)+'-'+m+'.csv', sep = ';', header = None)
dfloc = dfloc.ix[1:]
dfloc.columns = dfnames
dfloc[dfloc.columns[2:13]] = dfloc[dfloc.columns[2:13]].apply(pd.to_numeric)
df = df.append(dfloc)
print(df)
df.to_excel('C:/Users/d_floriello/Documents/PUN/'+city+' '+ anno + '_updated.xlsx')
return df
###############################################################################