import requests
import gzip
import json
# gz文件地址
url='https://shilupan-basic-user-pro.oss-cn-shanghai.aliyuncs.com/carrier/moxie/origin/39984791325599432283.txt.gz?Expires=1527497273&OSSAccessKeyId=TMP.AQEh4F-lRNcOsquy3PtvrvhnvooWgj7QI_I5xqpA2V3-yrr0PyQtNKGRWerJADAtAhUAlpsBiOtD6FNQMF9DmtiW3ZO39owCFGME2n4KgLW0ZknE1uQ_rOAPRQoC&Signature=oOn5739IptAlhhh%2F04ckqjQFdTY%3D'
response=requests.get(url)
html=response.text
response.encoding = 'utf-8'
# 解压后为bytes类型
html1 = gzip.decompress(response.content)
print(html)
print(type(html1))
#转化成str
html2=html.decode()
print(type(html2))
# 转为json
html3=json.loads(html2)
print(html3)
print(type(html3))
python处理gz压缩文件,解压并转化为json
最新推荐文章于 2024-04-28 19:58:47 发布