簡體   English   中英

如何將 python 字節碼解碼為 ASCII? (硒。從網絡響應中獲取 xml)

[英]How to decode python byte code to ASCII? (Selenium. Getting xml from network response)

如何將pyhon字節碼解碼為ascii? 我使用 selenium from.network 響應提取數據。 應該得到 xml。得到:['b'\xa5\xff\xff\xc7\x88\xe4\xb4\xd7\x03\xa0\x11:|\xce\xdb\xb7\x0f\xf1\xdf\xfc\x1f \xdb\x93\x91^\xbc\xa3\xdd\xc2\x02V\x00\xba$\xbd\x10\xd2\xd0E\xf2\x90\xb6\xca\xee\x10\xbf\xbf_\xbf\xfc \xef?\xe9\x13{H\xf1\xa1\xa0\x00\x1c\x01(\x80\x1c\x81\x02(s\xe7Z\xf3\xb3N\xf5L\xdc>\xe7\x8f\xbbwl\ xbf\x99\x91\xd4O\xde\xb4,\xf3PH\x02L1\x00\xc98\xc3,\x13:\x82\xc6\xc2\xa6Bd"k\xcb\x9d(\xb9\x13%WQr\x15% W\xb1\xe5J\t\x9e;\x8a\x03\x99\x06H\xd0\x8f\xd8\xfe\x9f9\xbc\xfc\x157\x111\xd7\x15\xaab\xfb\xe8.\xab\ xee\xfc\x9b\xeeu\x10<d\x04\x06Y\xa8\xd7\x9f\x11...

代碼:... for request in driver.requests: if request.response: text_file.write(str(request.response.body))

我試過: decoded = request.response.body.decode('ascii')request.response.body.decode('utf-8')或 cp1251/1252 我得到:UnicodeDecodeError: 'ascii' codec can't解碼 position 中的字節 0xa5 0:序號不在范圍內(128)

回復應為 xml (~1,5mb) 附照片回復

如果我使用: decoded = base64.b64decode(request.response.body)

我越來越像:b'T@\x00\xad\x9a\xb5\xba\xfa3u\xca\x84PG\xbd\x8a\xab\x1f\xcdcJ%\r\xd4\xff\x0c$)\x9a >....不是所期望的。 結合 decoded = base64.b64decode(request.response.body).decode('ascii') 也無濟於事:UnicodeDecodeError: 'ascii' codec can't decode byte 0x85 in position 0: ordinal not in range(128)

請幫幫我。

這是因為 Header 'Content-Encoding': 'br' 安裝 brotly 幫助。 同時刪除此消息有很大幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM