encoding problem with BeautifulSoup - problem when writing parsed text to file

Chris Angelico rosuav at gmail.com
Thu Oct 6 01:00:31 EDT 2011


On Thu, Oct 6, 2011 at 3:39 PM, Greg <gregor.hochschild at googlemail.com> wrote:
> Brilliant! It worked. Thanks!
>
> Here is the final code for those who are struggling with similar
> problems:
>
> ## open and decode file
> # In this case, the encoding comes from the charset argument in a meta
> tag
> # e.g. <meta charset="iso-8859-2">
> fileContent = fileObj.decode("iso-8859-2")
> f.write(text.encode('utf-8'))

In other words, when you decode correctly into Unicode and encode
correctly onto the disk, it works!

This is why encodings are so important :)

ChrisA



More information about the Python-list mailing list