これは楽。
情報源
1. インストール
最新バージョン
現時点での最新は3.8。対してapt
は2.9。
$ apt search googler | grep -A 2 'googler' googler/stable,stable,stable,stable,stable 2.9.0-1 all Power tool to Google(Web & News) and Google Site Search from the terminal
しかしReadMeにはv2.7以降には自己アップグレード機能があるという。基本的にenable
なのかな? なら2.9でも3.8にアップグレードできる?
$ make disable-self-upgrade
信じて2.9をインストールする。
sudo apt install -y googler
やはり2.9……。
$ googler --version
2.9
ヘルプを見ると-u
でアップグレードできるらしい。
$ googler --help | grep 'upgrade' -u, --upgrade perform in-place self-upgrade
さっそくアップグレードする。sudo
が必要だった。
$ sudo googler -u
Downloading https://raw.githubusercontent.com/jarun/googler/v3.8/googler
Upgraded to v3.8.
アップグレードできた! たぶんこれでGoogleのHTML構造が変化しても作者たちが対応してくれると期待する。
$ googler --version
3.8
2. ヘルプ
$ googler --help usage: googler [-h] [-s N] [-n N] [-N] [-c TLD] [-l LANG] [-x] [-C] [--colors COLORS] [-j] [-t dN] [-w SITE] [--unfilter] [-p PROXY] [--noua] [--notweak] [--json] [--url-handler UTIL] [--show-browser-logs] [--np] [-u] [--include-git] [-v] [-d] [KEYWORD [KEYWORD ...]] Google from the command-line. positional arguments: KEYWORD search keywords optional arguments: -h, --help show this help message and exit -s N, --start N start at the Nth result -n N, --count N show N results (default 10) -N, --news show results from news section -c TLD, --tld TLD country-specific search with top-level domain .TLD, e.g., 'in' for India -l LANG, --lang LANG display in language LANG -x, --exact disable automatic spelling correction -C, --nocolor disable color output --colors COLORS set output colors (see man page for details) -j, --first, --lucky open the first result in web browser and exit -t dN, --time dN time limit search [h5 (5 hrs), d5 (5 days), w5 (5 weeks), m5 (5 months), y5 (5 years)] -w SITE, --site SITE search a site using Google --unfilter do not omit similar results -p PROXY, --proxy PROXY tunnel traffic through an HTTP proxy; PROXY is of the form [http://][user:password@]proxyhost[:port] --noua disable user agent --notweak disable TCP optimizations and forced TLS 1.2 --json output in JSON format; implies --noprompt --url-handler UTIL custom script or cli utility to open results --show-browser-logs do not suppress browser output (stdout and stderr) --np, --noprompt search and exit, do not prompt -u, --upgrade perform in-place self-upgrade --include-git when used with --upgrade, get latest git master -v, --version show program's version number and exit -d, --debug enable debugging omniprompt keys: n, p fetch the next or previous set of search results index open the result corresponding to index in browser f jump to the first page o [index|range|a ...] open space-separated result indices, numeric ranges (sitelinks unsupported in ranges), or all, in browser open the current search in browser, if no arguments O [index|range|a ...] like key 'o', but try to open in a GUI browser g keywords new Google search for 'keywords' with original options should be used to search omniprompt keys and indices c index copy url to clipboard u toggle url expansion q, ^D, double Enter exit googler ? show omniprompt help * other inputs issue a new search with original options Version 3.8 Copyright © 2008 Henri Hakkinen Copyright © 2015-2019 Arun Prakash Jana <engineerarun@gmail.com> Zhiming Wang <zmwangx@gmail.com> License: GPLv3 Webpage: https://github.com/jarun/googler
3. 使ってみる
googler 検索キーワード
すぐに以下の要望が出た。設定が必要そう。
4. 操作方法
googler (? for help) ? omniprompt keys: n, p fetch the next or previous set of search results index open the result corresponding to index in browser f jump to the first page o [index|range|a ...] open space-separated result indices, numeric ranges (sitelinks unsupported in ranges), or all, in browser open the current search in browser, if no arguments O [index|range|a ...] like key 'o', but try to open in a GUI browser g keywords new Google search for 'keywords' with original options should be used to search omniprompt keys and indices c index copy url to clipboard u toggle url expansion q, ^D, double Enter exit googler ? show omniprompt help * other inputs issue a new search with original options
1<Enter>
と入力すればページを参照できる。
n<Enter>
で次のページを表示しても1
から始まる。何ページ目か表示して欲しい。
5. 設定
快適に見るためにはいくつか設定が必要だった。
- ブラウザの指定
- 1回あたりの表示数
5-1. ブラウザの指定
export BROWSER=w3m
一回限りなら以下。
BROWSER=w3m googler query
ReadMe参照。
これでデフォルトのchromiumからw3mにできる。毎回ブラウザ設定するのが面倒なので以下のようにする。
~/.bashrc
export BROWSER=w3m
5-2. 1回あたりの表示数
googler -n 5 検索キーワード
テキストブラウザで表示件数10
だと後半しか見れない。そこで表示件数を5
にした。
6. JSON
なんとJSON化までしてくれる。
$ googler -n 3 --json linux [ { "abstract": "Linux(リナックス、他の読みは後述)とは、Unix系オペレーティングシステムカーネルであるLinuxカーネル、およびそれをカーネルとして周辺を整備したシステム(GNU/Linuxシステムも参照)である。", "title": "Linux - Wikipedia", "url": "https://ja.wikipedia.org/wiki/Linux" }, { "abstract": "2018年9月20日 ... Linuxでできることを10個、3分間でわかるようにまとめてみた。Linuxをはじめて勉強しようとしている方や、Linuxについて誰かに聞かれて答えに困ったという方向け。", "title": "【初心者向け】3分でわかるLinuxでできることまとめ 10選", "url": "https://eng-entrance.com/you_can_do_linux" }, { "abstract": "日本で提供されている Linux 関連の情報の中心的ページです。Linux/OSSニュース、これからLinuxを学ぶ方向けのリソース集、それにLinux、オープンソースの分野で活躍されている方々のインタビューやコラムなど、初心者から上級者まで役に立つ情報が満載 ...", "title": "Linux.com | 日本のリナックス/OSS情報ポータル", "url": "https://jp.linux.com/" } ]
これは素晴らしい! 色々と応用できそう。
GoogleAPIもあるが以下のような面倒があり使う気になれなかった。
不満
- w3m
- 操作方法がわかりづらい
- テキストコピーできない
対象環境
- Raspbierry pi 3 Model B+
- Raspbian stretch 9.0 2018-11-13
$ uname -a Linux raspberrypi 4.14.98-v7+ #1200 SMP Tue Feb 12 20:27:48 GMT 2019 armv7l GNU/Linux