https://mp.weixin.qq.com/s/KRnExA17mTnYG_nAdyJ9Nw(平哥)
https://blog.csdn.net/weixin_57440207/article/details/116402943
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/c66323275d64dc11edc186ca6be3e9e8.png)
如何在pycharm加环境变量
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/ddeae07874c06d7b2803c10c7a8f5659.png)
import requests
headers = {
'Host':'webcast3-normal-c-lq.amemv.com',
'Connection':'keep-alive',
'Cookie':'odin_tt=7aef19e21d7d32c2c272bbcbc85e32d1339c0f636c77c8eab64775a75fda52ac5de50c23ba90378590e3a1363addba271c3e4169b752feec1198bcaf3ea483e8; install_id=1601359907134408; ttreq=1$f96855224d3b8a10cafc2c1bf1c495e82bedc2b8; odin_tt=7aef19e21d7d32c2c272bbcbc85e32d1339c0f636c77c8eab64775a75fda52ac5de50c23ba90378590e3a1363addba271c3e4169b752feec1198bcaf3ea483e8; install_id=1601359907134408; ttreq=1$f96855224d3b8a10cafc2c1bf1c495e82bedc2b8',
'response-format':'protobuf',
'passport-sdk-version':'17',
'sdk-version':'2',
'X-SS-DP':'1128',
'x-tt-trace-id':'00-80083c4b0d35065193c44e8273ba0468-80083c4b0d350651-01',
'User-Agent':'com.ss.android.ugc.aweme/110801 (Linux; U; Android 6.0.1; zh_CN; Nexus 6P; Build/MTC20L; Cronet/TTNetVersion:71e8fd11 2020-06-10 QuicVersion:7aee791b 2020-06-05)',
'Accept-Encoding':'gzip, deflate, br',
'X-Gorgon':'8404e09e0005e94e4072ce8ae17f03f29ad321285d5f80bbea69',
'X-Khronos':'1625645660',
}
url = 'https://webcast3-normal-c-lq.amemv.com/webcast/room/info/?pack_level=4&room_id=6982091190829419302&webcast_sdk_version=1590&webcast_language=zh&webcast_locale=zh_CN&os_api=23&device_type=Nexus%206P&ssmix=a&manifest_version_code=110801&dpi=560&uuid=867981022264181&app_name=aweme&version_name=11.8.0&ts=1625645660&cpu_support64=true&storage_type=1&app_type=normal&ac=wifi&host_abi=arm64-v8a&update_version_code=11809900&channel=samsungapps&_rticket=1625645660867&device_platform=android&iid=1601359907134408&version_code=110800&mac_address=48%3ADB%3A50%3A4A%3AA8%3AFD&cdid=80c5380e-7381-47cf-9012-de6609dd7dfd&openudid=9423101c8a88e6b9&device_id=932820075431144&resolution=1440*2392&os_version=6.0.1&language=zh&device_brand=google&aid=1128'
res = requests.get(url,headers=headers)
res_content = res.content
with open(r'demo.bin', 'wb')as f:
f.write(res_content)
b = os.system('protoc --decode_raw < demo.bin > demo.txt')
print('done')
import scratch_pb2
address_book = scratch_pb2.AddressBook()
person = address_book.people.add()
person.id = 11
person.name = 'Sam'
person.email = 'study.com'
phone_number = person.phones.add()
phone_number.number = '18028282828'
phone_number.type = 20
enco_str = address_book.SerializeToString()
print(enco_str)
enco_str += enco_str
with open(r'scratch.bin', 'wb')as f:
f.write(enco_str)
address_book.ParseFromString(enco_str)
for i in address_book.people:
print(i.id)
print(i.name)
print(i.email)
for phone_number in i.phones:
print(phone_number.number)
print(phone_number.type)
import re
def string_escape(s, encoding='utf-8'):
return (s.encode('latin1')
.decode('unicode-escape')
.encode('latin1')
.decode(encoding))
decode_str_list = []
with open('./xixi.txt','r') as f:
xixi = f.read()
need_str = xixi
need_str_list = need_str.split('\\')
print(need_str_list,'need_str_list++')
num = 0
decode_list = []
pingjie_str = ''
for n in need_str_list[1:]:
n = n.replace('\"','')
num += 1
decode_str_16 = hex(int(n,8))
print(decode_str_16,'decode_str_16++')
decode_str_16 = re.sub('0x','x',decode_str_16)
decode_list.append(decode_str_16)
if num == 3:
pingjie_str = '\\' + '\\'.join(decode_list)
try:
decode_str = string_escape(pingjie_str)
print(decode_str, 'decode_str+++')
decode_str_list.append(decode_str)
except:
pass
num = 0
decode_list = []
pingjie_str = ''
print(''.join(decode_str_list))
''' scratch.proto文件的结构
syntax = "proto3";
message Person {
string name = 1;
int32 id = 2;
string email = 3;
enum PhoneType { // 枚举类型,枚举类型应该不会有message
MOBILE = 0;
// HOME = 1;
// WORK = 2;
}
message PhoneNumber {
string number = 1;
PhoneType type = 2;
}
repeated PhoneNumber phones = 4;
}
message AddressBook {
repeated Person people = 1;
}
'''