Updating parsing according to status page

This commit is contained in:
Charlie Jacomme 2015-09-29 19:41:53 +02:00
parent ea4d25f597
commit 3dd845d333

View file

@ -20,16 +20,16 @@ COLOR_INFOS = {
COLORS = COLOR_INFOS.keys()
CONS_CLASS_BLOCK = {
color: re.compile(".*consumable-block-"+color.capitalize() +".*")
color: re.compile(".*gauge "+color.capitalize() +".*")
for color in COLORS
}
def ffindconsomable(color, raw):
"""Retrouve la couleur `color` dans raw"""
couleur=raw.findAll('div', attrs={"class":CONS_CLASS_BLOCK[color]})
couleur_toner=couleur[0].findAll('p',attrs={"class":'data percentage'})[0].string
couleur_toner=couleur[0].findAll('span')[0].string
couleur_toner=couleur_toner.split('%')[0]
couleur_tambour=couleur[1].findAll('p',attrs={"class":'data percentage'})[0].string
couleur_tambour=couleur[1].findAll('span')[0].string
couleur_tambour=couleur_tambour.split('%')[0]
try:
couleur_tambour=re.sub('[^\.0-9]', '', couleur_tambour.decode())
@ -56,7 +56,7 @@ if __name__ == '__main__':
else:
page = requests.get(URL, verify=CA)
raw=BeautifulSoup.BeautifulSoup(page.text)
for color in COLORS:
toner, tambour = ffindconsomable(color, raw)
print('{}_toner.value {}'.format(color, toner))