前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >推荐一款命令行搜索 Google 的工具 Googler

推荐一款命令行搜索 Google 的工具 Googler

作者头像
iMike
发布2019-06-11 17:54:52
2.7K0
发布2019-06-11 17:54:52
举报
文章被收录于专栏:运维之美运维之美

我们每天都要在网上寻找信息. 你也可以在网上找到任何信息. 因此搜索引擎也被设计成能够帮助我们从垃圾中快速筛选出有用信息的样子.

常用的搜索引擎有 Google, Bing, 和 DuckDuckGo. 不过它们都有一个共同点,那就是需要用浏览器(比如 Firefox 和 Chromium)来访问.

一般情况下这都不是什么问题; 但是如果你只有终端环境而没有 GUI 和浏览器怎么办呢, 如果你有 GUI 和浏览器但是你只想在不离开终端的情况下做一个快速搜索怎么办呢.

为此, Googler 诞生了.

注意: Googler 并不隶属于 Google .

什么是 Googler ?

Googler 是一个让你在命令行使用 Google (Web & News) 和 Google Site Search 的小工具,它虽然小巧但功能强大.

Googler 最初是为想在无 X 环境下使用 Google 的人所设计的. 你可以将它与像 lynx 或 links 这样的基于文本的浏览器整合,以便在命令行直接打开搜索结果. 但是现在它已经发展成为一个非常方便,非常灵活的工具了. 其功能也有了大大的扩展.

如何安装 Googler ?

Googler 需要 Python 3.3 以上版本支持. 且仅支持每个次要版本的最新补丁版本.

Googler 现在已经支持大多数发行版本来通过包管理器安装,下面以几个常见的发行版本为例:

代码语言:javascript
复制
# Debian / Ubuntu
$ apt-get install googler

# Fedora 
$ dnf install googler

# macOS
$ brew install googler

如果你使用的发行版本不支持通过包管理器安装,还有一个更简单的方法, Googler 只是一个独立的脚本, 你只需要下载这个文件就行了.

代码语言:javascript
复制
$ sudo curl -o /usr/local/bin/googler https://raw.githubusercontent.com/jarun/googler/v3.8/googler && sudo chmod +x /usr/local/bin/googler

如果你需更新 Googler ,只需运行以下命令:

代码语言:javascript
复制
$ sudo googler -u

更多安装方式可参考官方文档:https://github.com/jarun/googler#installation

怎么用 Googler ?

Googler 会显示出搜索结果的标题,URL 以及摘要,你可以直接从终端调用浏览器访问这些搜索结果. 搜索结果以页的形式组织,你可以上下进行翻页. 同时你还可以在同一个 Googler 实例上进行连续的搜索.

你可以指定搜索结果的数量, 限制搜索 bt duration 等等, 而且搜索结果非常清爽,没有那些广告和流氓网址. Shell 补全功能使得你无需记忆任何参数.

代码语言:javascript
复制
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

让我们看一些实际的例子.

  • 你可以使用 Googler 搜索任意字符串. 例如这里我尝试搜索最匹配 [Linux and Ubuntu news] 的网站.

查看更多搜索结果

  • 更厉害的是, 你可以使用 -w 限制在某个特定的网站中执行搜索(比如我要搜索 kde). 我这里同时指定每页只显示 3 个结果 (默认为 10 个结果).

更多的例子

  • Google 搜索 hello world :
代码语言:javascript
复制
$ googler hello world 
  • 在站点 imdb.com 中搜索关键字 jungle book,搜索的结果要在最近 14 个月内更新过的. 从第 3 个结果开始,显示 15 个结果:
代码语言:javascript
复制
$ googler -n 15 -s 3 -t m14 -w imdb.com jungle book 
  • 阅读关于 gadgets 相关的最新消息:
代码语言:javascript
复制
$ googler -N gadgets 
  • 查看更多帮助:
代码语言:javascript
复制
$ googler -h

或者

代码语言:javascript
复制
$ man googler 

Googler 功能一览

1. 与文本浏览器实现整合

Googler 天然与文本浏览器相适应,只需要设置一下 BROWSER 环境变量即可. 像这样:

代码语言:javascript
复制
$ export BROWSER=w3m 

若只是临时设置,可以这样:

代码语言:javascript
复制
$ BROWSER=w3m googler query 

2. 终端阅读模式或者说阅读者视图

Googler 可以很方便的与其他工具整合, 给你提供一个无干扰的阅读环境. 详细信息可参见: http://t.cn/ECy4lB1 .

3. 配色

Googler 允许你通过一个 6 位字符的字符串来自定义配色方案, 其格式与 BSD LSCOLORS 一致.

4. 其它一些特性

  • 快速,纯净(没有广告, 流氓网址(stray URL)以及其他乱七八糟的东西), 可以自定义配色
  • 支持 Google 关键字
  • 直接在浏览器中打开排名第一的搜索结果
  • 文档齐全, man 页面中包含很多案例演示
  • 连续搜索: 可以在不退出的情况下开始新的搜索

结论

Googler 的受众范围有限,但如果你更喜欢终端,它是一个不错的好工具. 虽然用的不多,但是我很喜欢 Googler,我会一直留着它. 想了解更多关于 Googler 的信息, 请访问它的官方页面:https://github.com/jarun/googler

来源:GitHub 原文:http://t.cn/ECycY9H 题图:来自谷歌图片搜索 版权:本文版权归原作者所有

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-06-04,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 奇妙的Linux世界 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 什么是 Googler ?
  • 如何安装 Googler ?
  • 如果你需更新 Googler ,只需运行以下命令:
  • 更多安装方式可参考官方文档:https://github.com/jarun/googler#installation
  • 怎么用 Googler ?
  • 更多的例子
  • Googler 功能一览
  • 结论
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档