[問題] 檔案處理 - 文字與二進位 - 混合使用

看板Python作者 (這個帳號是掛網用)時間14年前 (2011/08/29 16:41), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
文字檔如下, 他其實是 http 的東西 , 但今天他被存成一個檔案 , 我要怎麼爬 header 然後抓裡面的資料 ? 怎樣才能一行一行讀 , 然後到了要 binary 的地方, 就用 binary 在處理 ?____ GET /13531.jsp?/ HTTP/1.1 User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0) Connection: Keep-Alive HTTP/1.1 200 OK Date: Thu, 17 Mar 2011 09:53:56 GMT Server: Apache/1.3.20 (Unix) (Red-Hat/Linux) accept-type: x-wav/y-img Content-Type: application/octet-stream Content-Length: 2 Age: 5 Via: 1.1 wsgnode2 你&...0?.....是.........&...0?..3i&...0?..1o(很多 ..............) GET /13548.jsp?/ HTTP/1.1 User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0) Connection: Keep-Alive HTTP/1.1 200 OK Date: Thu, 17 Mar 2011 09:53:58 GMT Server: Apache/1.3.20 (Unix) (Red-Hat/Linux) accept-type: x-wav/y-img Content-Type: application/octet-stream Content-Length: 2 Age: 2 Via: 1.1 wsgnode2 5.23490........vj...波ㄉˇ..... GET /13554.jsp?/ HTTP/1.1 User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0) Connection: Keep-Alive HTTP/1.1 200 OK Date: Thu, 17 Mar 2011 09:54:13 GMT Server: Apache/1.3.20 (Unix) (Red-Hat/Linux) accept-type: x-wav/y-img Content-Type: application/octet-stream Content-Length: 43 Age: 15 Via: 1.1 wsgnode2 ........<...>,SQ.@.........V&...0?.....rJ.j -- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.135.121.210

08/29 17:26, , 1F
open(filename, 'rb') 就行了
08/29 17:26, 1F

08/29 18:23, , 2F
你的問題跟我一樣,用二進位的方式讀就行~
08/29 18:23, 2F
文章代碼(AID): #1EMr2bq7 (Python)
文章代碼(AID): #1EMr2bq7 (Python)