You are using str(equipment)
without a codec; you are encoding the Tag object to ASCII.
Don't use str
; get the text once as a unicode value. And use a mapping and a loop instead of so many if
statements.
In this case, the style
attribute is all you need to test against:
types = {
'#b0c3d9': 'Common',
'#5e98d9': 'Uncommon',
'#4b69ff':'Rare',
'#8847ff': 'Mythical',
'#b28a33': 'Immortal',
'#d32ce6': 'Legendary',
'#eb4b4b': 'Ancient',
'#ade55c': 'Arcana'
}
for equipment in eqs:
style = equipment.div.attrs.get('style', '')
textcontent = equipment.getText().encode('utf8')
for key in types:
if key in style:
f2.write('{}, {}'.format(textcontent, types[key])
Most likely, however, those color codes are in an attribute on the equipment
tag; look just in the tag value, or use a .find()
call to narrow down your searches.