<div><br></div><div>Hi,</div><div><br></div><div>I'am trying to write a mass html downloader, and it processes files after it downloaded them. I have problems with encodings, and decodings. Sometimes I get UnicodeDecodeErrors, or </div>
<div>I get half-pages in after processing part. Or more generally, some things don't feel right. Can you check my approach, and provide me some feedback please? Here is what I am doing.</div><div><br></div><div>1) send a HEAD request to file's source to get file encoding, set encoding variable accordingly.</div>
<div>2) if server doesn't provide an encoding, set encoding variable as utf-8</div><div>3) read html page from internet, read it to a variable let's say content.</div><div>4) in this step, I need to parse the content I get, because I will search for further links \</div>
<div>        I feed content to parser (subclass of HTMLParser.HTMLParser) like this -> content.decode(encoding)</div><div>5) open a file in binary mod open(file_path,"wb")</div><div>6) I write as I read without modifing.</div>
<div><br></div><div>##########</div><div># After processing part....</div><div>##########</div><div><br></div><div>(Note: encoding variable is same as the downloading part)</div><div><br></div><div>1) open local file in binary mod for reading file_name = open(file_path,"rb")</div>
<div>2) decode the file contents into a variable => decoded_content = file_name.read().decode(encoding)</div><div>3) send decoded content to a parser, parser contstruct new html content. (as str)</div><div>4) open same file for writing, in binary mod, write parsers output like this: file_name.write(parser.output.encode(encoding))</div>
-- <br><a href="http://yasar.serveblog.net/" target="_blank">http://yasar.serveblog.net/</a><br><br>