指定したURLや様々なソースから様々な形式でアーカイブ出来る. Youtubeのビデオgit等もアーカイブ可能.
Python3製 MIT Licence
これでだいたいのものはアーカイブできるようになる.問題はスマートフォンなどでURLが見えなく,共有ボタンがないようなもの.proxyを立ててそれのlogを元にスクレイピングすればいけそう. ゲームなども引っかかるだろうけどそれは除外しないとBANされそう><
今回は Debian Buster, Debian sid amd64, Ubuntu 18.04 amd64 で確認
必要なパッケージの導入
$ sudo apt install python3 python3-pip python3-distutils git wget curl youtube-dl $ sudo apt install chromium
ArchiveBox入手
$ git clone https://github.com/pirate/ArchiveBox $ cd ArchiveBox
help
$ ./archive --help ArchiveBox: The self-hosted internet archive. Documentation: https://github.com/pirate/ArchiveBox/wiki UI Usage: Open output/index.html to view your archive. CLI Usage: echo 'https://example.com' | ./archive ./archive ~/Downloads/bookmarks_export.html ./archive https://example.com/feed.rss ./archive 15109948213.123
./setup
を使うと必要なパッケージの導入なども面倒を見てくれるらしいが未確認$ git clone https://github.com/pirate/ArchiveBox $ cd ArchiveBox $ git checkout django $ sudo ./bin/archivebox-setup $ pip3 install . $ ~/.local/bin/archivebox [6/9648] ArchiveBox v0.4.3: The self-hosted internet archive. Active data directory: /home/pi/src/ArchiveBox/output Usage: archivebox [command] [--help] [--version] [...args] Commands: help Print the ArchiveBox help message and usage version Print the ArchiveBox version and dependency information init Initialize a new ArchiveBox collection in the current directory config Get and set your ArchiveBox project configuration values add Add a new URL or list of URLs to your archive remove Remove the specified URLs from the archive update Import any new links from subscriptions and retry any previously failed/skipped links list List, filter, and export information about archive entries shell Enter an interactive ArchiveBox Django shell manage Run an ArchiveBox Django management command status Print out some info and statistics about the archive collection server Run the ArchiveBox HTTP server schedule Set ArchiveBox to regularly import URLs at specific times using cron Example Use: mkdir my-archive; cd my-archive/ archivebox init archivebox status archivebox add https://example.com/some/page archivebox add --depth=1 ~/Downloads/bookmarks_export.html archivebox list --sort=timestamp --csv=timestamp,url,is_archived archivebox schedule --every=week https://example.com/some/feed.rss archivebox update --resume=15109948213.123 Documentation: https://github.com/pirate/ArchiveBox/wiki
$ mkdir output $ ~/.local/bin/archivebox init $ ~/.local/bin/archivebox add $URL
$ ./archive http://example.com/ [*] [2019-08-16 16:53:23] Downloading http://example.com/ > output/sources/example.com-1565942003.txt [*] [2019-08-16 16:53:24] Parsing new links from output/sources/example.com-1565942003.txt... > Adding 1 new links to index (parsed import as Plain Text) [*] [2019-08-16 16:53:24] Saving main index files... √ output/index.json √ output/index.html [▶] [2019-08-16 16:53:24] Updating content for 101 pages in archive... [+] [2019-08-16 16:53:24] "http://www.iana.org/domains/example" http://www.iana.org/domains/example > output/archive/1565942004 > title > favicon > wget > pdf > screenshot > dom > media > archive_org
$ ls -lA output/archive/1565942004 total 636 -rwxr-xr-x 1 matoken matoken 78 Aug 16 16:53 archive.org.txt -rwxr-xr-x 1 matoken matoken 902 Aug 16 16:53 favicon.ico -rwxr-xr-x 1 matoken matoken 15066 Aug 16 16:53 index.html -rwxr-xr-x 1 matoken matoken 7473 Aug 16 16:53 index.json drwxr-xr-x 2 matoken matoken 4096 Aug 16 16:53 media -rwxr-xr-x 1 matoken matoken 10086 Aug 16 16:53 output.html -rwxr-xr-x 1 matoken matoken 354735 Aug 16 16:53 output.pdf -rwxr-xr-x 1 matoken matoken 234292 Aug 16 16:53 screenshot.png drwxr-xr-x 2 matoken matoken 4096 Aug 16 16:53 warc drwxr-xr-x 6 matoken matoken 4096 Aug 16 16:53 www.iana.org
環境変数や設定ファイルで振る舞いを変更できる
$ cp etc/ArchiveBox.conf.default ~/.ArchiveBox.conf $ vi ~/.ArchiveBox.conf
書き出しディレクトリ,タイムアウト,取得するコンテンツの種類,解像度,ユーザーエージェント,各種コマンドパス等々.
ArchiveBoxで紹介されている方法ではPocket側でRSSを一般公開してそのFeedを指定する * Pocket: プライバシー管理
RSS フィード あなたの RSS フィードは非公開で、パスワードで保護されています - RSS フィードのパスワード保護を解除. 注:フィードリーダーによっては、パスワード保護されているフィードを読めない場合があります.
RSS フィード あなたの RSS フィードは公開されています - RSS フィードをパスワードで保護 すべてのアイテムフィード
https://getpocket.com/users/*sso1456706866592e34/feed/all
$ ./archive https://getpocket.com/users/*sso1456706866592e34/feed/all
APIを使うとタグを指定したりと細かく制御可能
プロファイルの場所は ~/.mozilla/firefox/profiles.ini
の内容を確認したり,$ firefox --ProfileManager
が参考になる.
$ bin/archivebox-export-browser-history --firefox ~/.mozilla/firefox/nern0ad8.default/places.sqlite Firefox history exported to: output/sources/firefox_history.json
この.jsonをArchiveBoxに
$ ./archive output/sources/firefox_history.json
規定値のデフォルトプロファイルの場合.書き出しファイルの変更はオプションなどでは指定できないので書き出しrenameしている.
$ bin/archivebox-export-browser-history --chrome ~/.config/google-chrome/Default/History && mv output/sources/chrome_history.json output/sources/chrome_history_`hostname`.json Chrome history exported to: output/sources/chrome_history.json
この.jsonをArchiveBoxに
$ ./archive output/sources/chrome_history_`hostname`.json
規定値のデフォルトプロファイルの場合.書き出しファイルの変更はオプションなどでは指定できないので書き出しrenameしている.
$ bin/archivebox-export-browser-history --chrome ~/.config/chromium/Default/History && mv output/sources/chrome_history.json output/sources/chromium_history_`hostname`.json Chrome history exported to: output/sources/chrome_history.json
この.jsonをArchiveBoxに
$ ./archive output/sources/chromium_history_`hostname`.json
ログインして設定できるサイトであればArchiveBoxで利用しているプロファイルでログインして設定しておく
日本のproxyを使うか日本IPのサーバを使うくらい?
$ ./archive Traceback (most recent call last): File "./archive", line 136, in <module> main(*sys.argv) File "./archive", line 98, in main update_archive_data(import_path=import_path, resume=resume) File "./archive", line 106, in update_archive_data all_links, new_links = load_links_index(out_dir=OUTPUT_DIR, import_path=import_path) File "/home/matoken/usr/local/ArchiveBox/archivebox/index.py", line 61, in load_links_index existing_links = parse_json_links_index(out_dir) File "/home/matoken/usr/local/ArchiveBox/archivebox/index.py", line 108, in parse_json_links_index links = json.load(f)['links'] File "/usr/lib/python3.7/json/__init__.py", line 296, in load parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw) File "/usr/lib/python3.7/json/__init__.py", line 348, in loads return _default_decoder.decode(s) File "/usr/lib/python3.7/json/decoder.py", line 340, in decode raise JSONDecodeError("Extra data", s, end) json.decoder.JSONDecodeError: Extra data: line 84619 column 2 (char 4486926)
$ git status On branch master Your branch is up to date with 'origin/master'. Untracked files: (use "git add <file>..." to include in what will be committed) output/ nothing added to commit but untracked files present (use "git add" to track)
output
ディレクトリ以外はcleanなので書き出し先を変えてみると動作した
$ OUTPUT_DIR=`mktemp -d` ./archive https://wiki.matoken.org/
error message からjsonが怪しい気がするのでoutput/index.jsonを確認
$ cat output/index.json | jq . > /dev/null parse error: Invalid numeric literal at line 84619, column 8
ArchiveBoxのエラーメッセージと同じ行を指しているみたい
json.decoder.JSONDecodeError: Extra data: line 84619 column 2 (char 4486926)
その当たりを表示してみると確かに壊れているよう
$ head -n 84622 output/index.json | tail "/home/matoken/usr/local/ArchiveBox/output/sources/stdin-1566136172.txt", "/home/matoken/usr/local/ArchiveBox/output/sources/stdin-1566134372.txt", "/home/matoken/usr/local/ArchiveBox/output/sources/stdin-1566132203.txt" ] } ] }estamp": "1565127715", "title": "<title>tkmiz: \u8a00\u8449\u306f\u6050\u308d\u3057\u3044</title>", "tags": "", "sources": [
手で修正したらまた動くようになった.
$ ./archive https://www.mbc.co.jp/news/ [*] [2019-08-16 18:53:59] Downloading https://www.mbc.co.jp/news/ [!] Failed to download https://www.mbc.co.jp/news/ 'utf-8' codec can't decode byte 0x8e in position 181: invalid start byte
起こるページは文字コードがShift_JISのよう
$ curl -s https://www.mbc.co.jp/news/ | grep -i charset= <meta http-equiv="content-type" content="text/html; charset=Shift_JIS" /> <script type="text/javascript" src="js/scrollsmoothly.js" charset="utf-8"></script> <link rel="stylesheet" type="text/css" href="/css/mbc_menu_import.css" charset="Shift-JIS"> <SCRIPT language="JavaScript" src="/js/mbcmenu.js" charset="Shift-JIS"></SCRIPT>
試しに小さなShift_JISのページを作ってみる
$ echo '<html> <head> <meta http-equiv="content-type" content="text/html; charset=Shift_JIS" /> </head> <body> こんにちは </body> </html>' | iconv -f UTF8 -t SJIS > hello_sjis.html
エラーになった
$ ./archive http://167.86.112.42/hello_sjis.html [*] [2019-08-16 19:02:10] Downloading http://167.86.112.42/hello_sjis.html [!] Failed to download http://167.86.112.42/hello_sjis.html 'utf-8' codec can't decode byte 0x82 in position 103: invalid start byte
Traceback (most recent call last): File "./archive", line 136, in <module> main(*sys.argv) File "./archive", line 98, in main update_archive_data(import_path=import_path, resume=resume) File "./archive", line 118, in update_archive_data archive_link(link_dir, link) File "/home/matoken/usr/local/ArchiveBox/archivebox/archive_methods.py", line 109, in archive_link patch_links_index(link) File "/home/matoken/usr/local/ArchiveBox/archivebox/index.py", line 177, in patch_links_index json_file_links = parse_json_links_index(out_dir) File "/home/matoken/usr/local/ArchiveBox/archivebox/index.py", line 108, in parse_json_links_index links = json.load(f)['links'] File "/usr/lib/python3.7/json/__init__.py", line 296, in load parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw) File "/usr/lib/python3.7/json/__init__.py", line 348, in loads return _default_decoder.decode(s) File "/usr/lib/python3.7/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.7/json/decoder.py", line 353, in raw_decode obj, end = self.scan_once(s, idx) json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 30575 column 303 (char 1611858)
jsonの該当行を見ると https://www.mbc.co.jp/
のコンテンツだった.恐らく一部のページでエラーとなり取得できない と同じ問題
コメント