I'm developing a web scraper for the Hoymiles monitoring system. One of the statistics I can get is historical data, but I get data in a strange format. After a lot of research and a search in the platform code, I found that in the post request made in addition to the headers and payload, they use a parameter that is the responseType: "arraybuffer". Hence, after more research, I found that arraybuffer is "a data type used to represent a generic, fixed-size binary data buffer".
My code is as follows:
def plants_data_historycal(self, authorization):
payload = '''
{
"mode":3,
"date":"2022-01-20"
}
'''
headers = {
'Accept': 'application/json, text/plain, */*',
'Accept-Encoding': 'gzip, deflate, br',
'authorization': authorization,
'Content-Type': 'application/json;charset=UTF-8',
'Origin': 'https://global.hoymiles.com',
'Referer': 'https://global.hoymiles.com/platform/login',
'Cookie': cookie,
'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Mobile Safari/537.36'
}
response = self.session.post(self.url+'/pvm-data/api/0/statistics/count_station_eq', headers=headers, data=payload)
if response.status_code != 200:
raise RuntimeError("A requisição falhou: %s", response)
print(response.text)
data = BeautifulSoup(response.text, 'html.parser')
data = json.loads(data.text)
return data
The response to my request looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20Y
pv_eqP��G�@H��[H�nH���H�0H��G���G�QH���G��H�JH�
�H`�H�1�H�ݗH@]sH��_H`j�H�!�H
The response.text before BeatifulSoup
\n\x011\n\x012\n\x013\n\x014\n\x015\n\x016\n\x017\n\x018\n\x019\n\x0210\n\x0211\n\x0212\n\x0213\n\x0214\n\x0215\n\x0216\n\x0217\n\x0218\n\x0219\n\x0220\n\x0221\n\x0222\n\x0223\x12e\n\x05pv_eq\x12\\\x00��G\x00�@H��[H\x00�nH���H�\x080H\x00��G���G�Q\x00H���G��\x02H�J\x03H�\r�H`�H�1�H�ݗH@]sH��_H`j�H�!�H���H`z�H I�H
To try to turn this string into something understandable, I tried to use the code available in the inspect option of the Hoymiles home page Chrome browser (https://global.hoymiles.com/platform/home). From there I found that they transformed the arraybuffer with the function
transformResponse: [
function (e) {
if ("string" == typeof e)
try {
e = JSON.parse(e);
} catch (e) {}
return e;
},
],
But even with that, the arraybuffer comes empty. So I turned the response as arraybuffer into a Uint8Array, but I can't understand what the data means.
Uint8Array {
0: 123
1:34
10:34
11:49
12:48
13:48
14:34
15:44
16:34
17: 100
18:97
19: 116
2: 115
20: 97
21:34
22:58
23:34
24: 34
25:44
26: 34
27: 109
28: 101
29: 115
3: 116
30: 115
31: 97
32: 103
33: 101
34: 34
35: 58
36: 34
37: 116
38: 111
39: 107
4: 97
40: 101
41: 110
42: 32
43: 118
44: 101
45: 114
46: 105
47: 102
48: 121
49: 32
5: 116
50: 101
51: 114
52: 114
53: 111
54: 114
55: 46
56: 34
57: 125
6: 117
7: 115
8:34
9:58
}
Does anyone know how to turn this into readable or understandable data?