id:Kodakana は
シェルスクリプトのことを語る

(複数の)ウェブページの URL を引数に取りテキストコンテンツを抽出、結合して出力するシェルスクリプト webslurp.sh Ver.0.3

  • --------
  • !/bin/bash

    Web slurping script

    for srcurl in "$@"
    do

    Download from web

    wget -q -O - $srcurl | nkf --utf8 -Lu > ~/.slurptmp.html

    Title content extraction

    title=`cat ~/.slurptmp.html | tr -d "\n" | grep "<title[^>]*>.*</title>\|<TITLE[^>]*>.*</TITLE>" | sed -e "s/\(.*<title[^>]*>\|.*<TITLE[^>]*>\)\(.*\)\(<\/title>.*\|<\/TITLE>.*\)/\2/g"`

    Headline generation

    headline="[$title]($srcurl)"

    Body content extraction

    body=`lynx -raw -dump -nolist ~/.slurptmp.html`

    Output

    echo "*"$'\t'"$headline"$'\n'$'\n'$'\n'"$body"$'\n'$'\n'
    done

  • --------
  • 使用例
    webslurp.sh http://www.google.co.jp/ http://h.hatena.ne.jp/
    webslurp.sh `cat urllist.txt`