を使用する次の行の場合urllib
:
# some request object exists
response = urllib.request.urlopen(request)
html = response.read().decode("utf8")
どの形式の文字列がread()
返されますか?私はPythonのドキュメントからそれを理解しようと試みてきましたが、それについてはまったく触れていません。なぜあるのdecode
ですか?decode
オブジェクトをutf-8またはutf-8にデコードしますか?どのフォーマットからどのフォーマットにデコードしますか?decode
ドキュメントにもそれについては何も記載されていません。Pythonのドキュメントがひどいのでしょうか、それとも標準的な規則を理解していないのでしょうか。
そのHTMLをUTF-8ファイルに保存したいと思います。通常の書き込みを行うだけですか、それとも何かに「エンコード」して書き戻す必要がありますか?
注:urllibが非推奨になっていることは知っていますが、現在urllib2に切り替えることはできません。