gzip解析 python
原创
©著作权归作者所有:来自51CTO博客作者JavaPub的原创作品,请联系作者获取转载授权,否则将追究法律责任
gzip解析
import psycopg2
import pandas as pd
import gzip
#连接数据库
conn = psycopg2.connect(database = 'block_data', user = 'root', password = '123456', host = '127.0.0.1', port = '5433')
curs=conn.cursor()
#编写Sql,只取前两行数据
# sql = 'select * from block_data_45 where id = 45055399'
sql = 'select * from block_data_15 where id = 15765135'
#数据库中执行sql命令
curs.execute(sql)
#获得数据
datas = curs.fetchall()
#遍历解析数据
for row in datas:
id = row[0]
data_info = row[1]
create_at = row[2]
print(id)
#gzip解析
print(gzip.decompress(data_info).decode('utf8'))
# print(df_result.id)
#关闭指针和数据库
curs.close()
conn.close()