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
| # -*- coding: utf-8 -*-
import requests, bs4#, csv, sys, os
#from datetime import date as datebis
#import chardet
url = 'http://www.meteociel.fr/climatologie/climato.php?'
payload = {"mois":5, "annee":2017, "submit":"OK"}
donnees_tot = "donnees_tot.txt"
try:
sess = requests.session()
r1 = sess.post(url, data=payload)
soup1 = bs4.BeautifulSoup(r1.text, 'html.parser')
with open(donnees_tot,"w") as f:
f.write(r1.text)
except:
pass
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:
elem_tot.append((el5.text))#.encode("utf-8"))
tot_villes = len(elem_tot)//6
elem_group = []
for i in range(0,tot_villes*6-6,6):
el = (elem_tot[i:i+6])
try:
el = el.replace(" °c","")
except:
pass
elem_group.append(el)
print(elem_group)
print(date)
moy_et_tot=elem_tot[tot_villes*6-6:]
print(moy_et_tot) |
Partager