やってみる

アウトプットすべく己を導くためのブログ。その試行錯誤すらたれ流す。

Raspbianでテキストブラウザによる軽量化

メモリ不足で落ちるので。

問題

ラズパイ3を使用中、頻繁にフリーズし、落ちる。作業が消える。絶望する。

解決

テキストブラウザで軽量化。

w3m

テキストブラウザのひとつ。

インストール

sudo apt-get install w3m w3m-img

w3m-imgもインストールしたが、LXTerminal 0.2.0では画像が表示されなかった)

起動

$ w3m --version
w3m version w3m/0.5.3+debian-19, options lang=en,m17n,image,color,ansi-color,mouse,gpm,menu,cookie,ssl,ssl-verify,external-uri-loader,w3mmailer,nntp,gopher,ipv6,alarm,mark,migemo
usage: w3m [options] [URL or filename]
...

Google検索結果

hatenaで検索した結果のページをみてみる。

$ w3m "https://www.google.co.jp/search?q=hatena&cad=h"

f:id:ytyaru:20180310105610p:plain

おお、見えている? と思ったら、見切れてる……

f:id:ytyaru:20180310105801p:plainf:id:ytyaru:20180310105806p:plain

カーソルキーで1文字分ずつ移動すると、右側のページがみえた。

これは見づらい……折り返してほしい。

  • q押下しyで終了
  • h, j, k, l でカーソル移動

問題点

  • 折り返してほしい
    • カーソル移動が面倒すぎる
  • 検索結果だけ見たい(上下、左右に不要な情報がある)

折り返せないか?

結論からいうと、見つけられなかった。

help
usage: w3m [options] [URL or filename]
options:
    -t tab           set tab width
    -r               ignore backspace effect
    -l line          # of preserved line (default 10000)
    -I charset       document charset
    -O charset       display/output charset
    -B               load bookmark
    -bookmark file   specify bookmark file
    -T type          specify content-type
    -m               internet message mode
    -v               visual startup mode
    -M               monochrome display
    -N               open URL of command line on each new tab
    -F               automatically render frame
    -cols width      specify column width (used with -dump)
    -ppc count       specify the number of pixels per character (4.0...32.0)
    -ppl count       specify the number of pixels per line (4.0...64.0)
    -dump            dump formatted page into stdout
    -dump_head       dump response of HEAD request into stdout
    -dump_source     dump page source into stdout
    -dump_both       dump HEAD and source into stdout
    -dump_extra      dump HEAD, source, and extra information into stdout
    -post file       use POST method with file content
    -header string   insert string as a header
    +<num>           goto <num> line
    -num             show line number
    -no-proxy        don't use proxy
    -4               IPv4 only (-o dns_order=4)
    -6               IPv6 only (-o dns_order=6)
    -no-mouse        don't use mouse
    -cookie          use cookie (-no-cookie: don't use cookie)
    -graph           use DEC special graphics for border of table and menu
    -no-graph        use ACII character for border of table and menu
    -s               squeeze multiple blank lines
    -W               toggle wrap search mode
    -X               don't use termcap init/deinit
    -title[=TERM]    set buffer name to terminal title string
    -o opt=value     assign value to config option
    -show-option     print all config options
    -config file     specify config file
    -help            print this usage message
    -version         print w3m version
    -reqlog          write request logfile
    -debug           DO NOT USE

-cols widthかと思ったが、違った。-cols 80, -cols width 80 としても変わらなかった。

ググってみた

文字化けして見れない……。

f:id:ytyaru:20180310120204p:plain

HTMLソースをみてみるとcharset指定していなかった。HTML4.1時代のコードっぽい。そして文字コードはたぶんShift-JISを使ってで書いているのだろう。RaspbianのChromiumだと文字化けする。Shift-JIS死ね。

英語でみるしかない。

せめて左右をページ単位で一発移動できるキーがあれば改善するのだが。

http://w3m.sourceforge.net/MANUAL.en.html#Key:orig

<, > でできた。

ページ単位移動
方向 キー
PgUp
PgDn
<
>

だが、上下、左右、ともにスクロールが必要であるせいで、操作量がとても増える……。折り返してくれよ……。

スクレイピング

これはもう、プログラミングするしかないか。

(邪魔な要素を排除できれば何でもいいのだが)

w3mはファイルも読み取れるようなので、スクレイピングしたあとの一時HTMLファイルをRAMディスクに配置して読み込ませれば、ほしい表示が得られそう?

そこまでやったら、もうw3mにこだわる必要なくなりそう。

所感

w3m、軽いのは素敵。でも、折り返し表示されず、見づらい。

日々使うにしては辛いか。

環境