答案 0 :(得分:0)
首先,我必须获取原始数据。我知道如何使用Firefox和Firebug插件将数据复制/粘贴到文件...手动。它使用angularjs.1.0.6
,由于Firebug,我从其中一个GET中获取原始数据:
GET https://thesite/api/data/1036493/heatEnergy/today?noCacheDummyValue=1459148624909
GET https://thesite/api/data/1036493/outTemp/today?noCacheDummyValue=1459148624905
GET https://thesite/api/data/1036493/heatEnergy/lastMonth?noCacheDummyValue=1459148708330
GET https://thesite/api/data/1036493/outTemp/lastMonth?noCacheDummyValue=1459148708321
如果我能做到这一点你会更好
- 直接入侵LAB.min.js数据?
- 使用我通常的登录帖子拨打curl
,然后使用上面的GET
收集数据
以下是我的curl
登录POST
来电的方式:
curl -o myraw.data --data-urlencode "userName=tutu&password=xx" 'https://thesite/api/login?noCacheDummyValue=1458825357449' \
-H 'Host: thesite' -H 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0' \
-H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate, br' \
-H 'X-Requested-With: XMLHttpRequest' \
-H 'Content-Type: application/json;charset=utf-8' \
-H 'Referer: https://thesite/mobile/app/app.html' \
-H 'Content-Length: 44' -H 'Cookie: JSESSIONID=1m5aputqimremdk95fgbtmgo9' \
-H 'Proxy-Authorization: Basic ??' -H 'DNT: 1' \
-H 'Connection: keep-alive'
但我一无所获。目前,我对Firebug
Copy Response Body / Paste
功能感到满意。
现在我认为我的原始数据看起来像JSON的东西:
[{"values":
[{"options":null,"webId":null,"value":"8.9","date":1458842750000,"writeValue":null,"unit":null}
,"options":null,"webId":null,"value":"9.1","date":1458842451000,"writeValue":null,"unit":null}
,{"options":null,
...
,{"options":null,"webId":null,"value":"5.5","date":1458774051000,"writeValue":null,"unit":null}],"unit":"°C"}]
现在我得到了我的数据,我觉得这很容易。但是我在尝试使用这个JSON数据时遇到了麻烦...我知道有些人已经尝试过了:Does LibreOffice Calc support JSON file importing/sorting?
我的JSON中只有常规模式,最近(重新)发现了sed
。所以我使用了我的新力量(找到我必须在替换值中添加一个真正的换行符是多么困难):
cat rawdata.txt | tr -d '\n' | sed 's/},{/\
/g' | sed 's/"options":null,"webId":null,"value"://' |\
sed 's/,"writeValue":null,"unit":null//' |sed 's/,"date":/;/' |\
sed 's/\[{"values":\[{//' |sed 's/}\],"unit":"°C"}\]/\
/' | sed 's/}\],"unit":"kWh"}\]/\
/' > pureData.csv
获取我的数据"temperature"
/ "timestamp"
:
ju@ju-HP-Compaq-dc7900-Small-Form-Factor:~/INSTALL/myproj$ cat pureData.csv
"8.9";1458842750000
"9.1";1458842451000
"9.3";1458842150000
"9.4";1458841851000
"9.7";1458841550000
"9.9";1458841251000
"10.0";1458840950000
...
......在这一点上很开心!当我绘制它时,它看起来就像我在Firefox窗口中所拥有的那样!
注意:我计算出我的时间轴是基于自1970年1月1日以来的毫秒数。
如果有兴趣的话,我写了一些东西,用curl
检索数据:How to use linux curl to login and retrieve data once logged?