Re: encoding problem with BeautifulSoup - problem when writing parsed text to file
- From: Chris Angelico <rosuav@xxxxxxxxx>
- Date: Thu, 6 Oct 2011 16:00:31 +1100
On Thu, Oct 6, 2011 at 3:39 PM, Greg <gregor.hochschild@xxxxxxxxxxxxxx> 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
.
- References:
- Prev by Date: Re: Is it possible to create C-style "main" function in Python? (for teaching purposes)
- Next by Date: selenium pyvirtualdisplay script on remote server
- Previous by thread: Re: encoding problem with BeautifulSoup - problem when writing parsed text to file
- Next by thread: Re: encoding problem with BeautifulSoup - problem when writing parsed text to file
- Index(es):
Relevant Pages
|