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
| # -*- coding: utf-8 -*-
import requests, bs4#, csv, sys, os
#from datetime import date as datebis
url0 = 'http://www.meteociel.fr/climatologie/climato.php?mois=mois_reel&annee=annee_reelle'
url=[]
for an in range(2003,2019,1):
for m in range(1,13,1):
url.append(url0.replace("mois_reel",str(m)).replace("annee_reelle",str(an)))
print(url)
donnees_tot = "donnees_tot.txt"
try:
sess = requests.session()
r1 = sess.post(url[-8])
soup1 = bs4.BeautifulSoup(r1.text, 'html.parser')
with open(donnees_tot,"w") as f:
f.write(r1.text)
except:
print("pas de connexion")
elem_tot=[]
tab1 = soup1.find_all('center')
for el1 in tab1:
el2= el1.find_all('center')
for d in el2:
date = d.find("h1")
for el3 in el2:
el4 = el3.find_all("td")
for el5 in el4:
el6 = (el5.text).replace(" °c","").replace(" mm","")
try:
elem_tot.append(float(el6))
except:
elem_tot.append(el6)
tot_villes = len(elem_tot)//6
elem_group = []
for i in range(0,tot_villes*6-6,6):
el = elem_tot[i:i+6]
elem_group.append(el)
print(elem_group)
print(date)
moy_et_tot=elem_tot[tot_villes*6-6:]
print(moy_et_tot)
print(tot_villes) |
Partager