I keep getting the below error and can't seem to get .encode('ascii', errors='ignore') to work.
eqs = soup.find_all('div', {'style': 'margin:7px 5px 0px;vertical-align:top;text-align:center;display:inline-block;line-height:normal;width:120px;'})
for equipment in eqs:
if '#b0c3d9' in str(equipment):
f2.write(equipment.getText() + ', Common\n')
if '#5e98d9' in str(equipment):
f2.write(equipment.getText() + ', Uncommon\n')
if '#4b69ff' in str(equipment):
f2.write(equipment.getText() + ', Rare\n')
if '#8847ff' in str(equipment):
f2.write(equipment.getText() + ', Mythical\n')
if '#b28a33' in str(equipment):
f2.write(equipment.getText() + ', Immortal\n')
if '#d32ce6' in str(equipment):
f2.write(equipment.getText() + ', Legendary\n')
if '#eb4b4b' in str(equipment):
f2.write(equipment.getText() + ', Ancient\n')
if '#ade55c' in str(equipment):
f2.write(equipment.getText() + ', Arcana\n')
I have tried:
f2.write(equipment.getText().encode('ascii', errors='ignore'))
and
f2.write(equipment.encode('ascii', errors='ignore').getText())
As well as some other things I am ashamed to post. Such as running it through the file that BeautifulSoup would later read from, but that just throws a different error. Thanks again for helping.
full traceback:
Traceback (most recent call last):
File "<pyshell#285>", line 1, in <module>
import D2soup1
File "D2soup1.py", line 86, in <module>
test()
File "D2soup1.py", line 30, in test
f2.write(equipment.getText() + ', Immortal\n')
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 5: ordinal not in range(128)
I am using string to parse out the box-shadow from the below html. I know it is probably not the best practice, but it was the only way I could think to grab it. Still new to BeautifulSoup.
<div style="margin:7px 5px 0px;vertical-align:top;text-align:center;display:inline-block;line-height:normal;width:120px;"><div style="margin-bottom: 5px;box-shadow:0px 0px 2px 4px #5e98d9;"><a href="/Pirate_Slayer%27s_Tricorn" title="Pirate Slayer's Tricorn"><img alt="Pirate Slayer's Tricorn" src="http://hydra-media.cursecdn.com/dota2.gamepedia.com/thumb/7/79/Pirate_Slayer%27s_Tricorn.png/120px-Pirate_Slayer%27s_Tricorn.png" width="120" height="80" srcset="http://hydra-media.cursecdn.com/dota2.gamepedia.com/thumb/7/79/Pirate_Slayer%27s_Tricorn.png/180px-Pirate_Slayer%27s_Tricorn.png 1.5x, http://hydra-media.cursecdn.com/dota2.gamepedia.com/thumb/7/79/Pirate_Slayer%27s_Tricorn.png/240px-Pirate_Slayer%27s_Tricorn.png 2x"></a></div>
str(equipment)there?