我想定期保存我的谷歌位置记录.
通常我使用Web接口:
https://maps.google.com/locationhistory/b/0
它还提供了一个导出数据的链接,如下所示:
https://maps.google.com/locationhistory/b/0/kml?startTime=1376604000000&endTime=1376690400000
如何每天下载此链接(及其固定的时间戳),包括使用WGET或curl登录?
简单地说它给我带来了302 Moved Temporarily
您将获得302 Moved Temporarily,因为您需要进行身份验证:Google正在将您重定向到其登录页面.
原文链接:https://www.f2er.com/bash/384498.html经过身份验证后,Google凭据会存储在浏览器Cookie中.如果您要下载Google地图位置历史记录链接,则必须提供带卷曲的浏览器Cookie. curl的-b选项允许您使用相对于Netscape/Mozilla cookie file format的cookies.txt.
Each line of the
cookies.txt
has seven tab-separated fields:
- domain – The domain that created AND that can read the variable.
- flag – A TRUE/FALSE value indicating if all machines within a given domain can access the variable. This value is set automatically by the browser,depending on the value you set for domain.
- path – The path within the domain that the variable is valid for.
- secure – A TRUE/FALSE value indicating if a secure connection with the domain is needed to * access the variable.
- expiration – The UNIX time that the variable will expire on. UNIX time is defined as the number of seconds since Jan 1,1970 00:00:00 GMT.
- name – The name of the variable.
- value – The value of the variable.
因此,最简单的解决方案是将浏览器cookie导出到cookies.txt文件并指示curl使用它们.在Chrome中,Cookie存储在sqlite3数据库中.您可以使用以下命令导出它们:
sqlite3 ~/.config/google-chrome/Default/Cookies \ 'select host_key,"TRUE",path,"FALSE",expires_utc,name,value from cookies where host_key like "%google.com"' \ | tr '|' '\t' > /tmp/cookies.txt
请注意host_key,例如限制导出Cookie的“%google.com”.
使用-b /tmp/cookies.txt调用curl以使用导出的cookie并对googles地图进行身份验证,您将能够下载google地图位置历史记录
curl -b /tmp/cookies.txt https://maps.google.com/locationhistory/b/0/kml\?startTime\=1376604000000\&endTime\=1376690400000
要避免将cookie存储在临时文件中,请使用以下命令:
curl -b <(sqlite3 ~/.config/google-chrome/Default/Cookies 'select host_key,value from cookies' | tr '|' '\t') https://maps.google.com/locationhistory/b/0/kml\?startTime\=1376604000000\&endTime\=1376690400000