WGET您的Google位置记录每天 [英] WGET your google location history daily
问题描述
我要定期保存我的google位置记录。
通常我使用Web界面:
https://maps.google.com/locationhistory/b/0
它还提供导出数据的链接,如下所示:
https://maps.google.com/locationhistory/b/0/kml?startTime=1376604000000&endTime=1376690400000
我如何每天下载此链接(并根据时间戳固定),包括使用WGET或curl登录?
只需wget它带给我一个 302暂时移动
c $ c>因为您需要验证:Google会将您重定向到其登录页面。
身份验证后,Google凭据将存储在浏览器Cookie中。如果您要下载Google地图位置记录链接,则必须提供 curl
的浏览器Cookie。 curl
的 -b
选项允许您使用 cookies.txt
相对于 Netscape / Mozilla Cookie文件格式。
cookies.txt
的每一行都有七个制表符分隔字段:
- domain - 创建AND可读取变量的域。
- 标记 - 表示给定域中的所有计算机是否都可以访问变量的TRUE / FALSE值。此值由浏览器自动设置,具体取决于您为域设置的值。
- 路径 - 变量对域有效的路径。
- secure - 一个TRUE / FALSE值,表示是否需要与该域的安全连接来访问该变量。
- 到期 - 变量将到期的UNIX时间。 UNIX时间定义为自1970年1月1日00:00:00 GMT以来的秒数。
- name - 变量的名称。
- 值 - 变量的值。
因此,最简单的解决方案是将浏览器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 like%google.com
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,TRUE FALSE,expires_utc,name,value from cookies'| tr'|''\t')https://maps.google.com/locationhistory/b/0/kml\?startTime\=1376604000000\ & endTime\ = 1376690400000
I want to save my google location history in a regular basis.
Usually I use the Webinterface: https://maps.google.com/locationhistory/b/0
it also provides a link to export data which looks like that:
https://maps.google.com/locationhistory/b/0/kml?startTime=1376604000000&endTime=1376690400000
How can I download this link (and its according timestamps fixed) daily including logging in using WGET or curl?
Simply wget it brought me an 302 Moved Temporarily
You get a 302 Moved Temporarily
because you need to be authenticated: Google is redirecting you to its login page.
Once authenticated, google credentials are stored in browser cookies. If you want to download the Google maps location history link, then you have to provide browser cookies with curl
. The -b
option of curl
allows you to use a cookies.txt
with respect to Netscape/Mozilla cookie file format.
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.
So the simplest solution is to export your browser cookies to a cookies.txt
file and instruct curl
to use them. In Chrome, cookies are stored in a sqlite3 database. You can export them with the following command:
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
Note the host_key like "%google.com"
which limits exported cookies.
Invoke curl
with -b /tmp/cookies.txt
to use the exported cookies and authenticate to googles maps and you will be able to download the google maps location history
curl -b /tmp/cookies.txt https://maps.google.com/locationhistory/b/0/kml\?startTime\=1376604000000\&endTime\=1376690400000
To avoid storing your cookies in a temporary file, use this command:
curl -b <(sqlite3 ~/.config/google-chrome/Default/Cookies 'select host_key, "TRUE", path, "FALSE", expires_utc, name, value from cookies' | tr '|' '\t') https://maps.google.com/locationhistory/b/0/kml\?startTime\=1376604000000\&endTime\=1376690400000
这篇关于WGET您的Google位置记录每天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!