擷取wiki某網頁資訊shell即擷取wiki子目錄資訊-shell

來源:互聯網
上載者:User

標籤:wiki getopts

#!/bin/bash


##################################################

##################################################


set -e


##需要參數

if [ $# -eq 0 ];then

    echo "需要參數,例如下面命令"

    echo "sh $0 -h"

    exit 1

fi


##shell需要jq命令

#apt-get install -y jq  1>/dev/null 2>&1 

##擷取 wiki tower記錄,下載到本地 towerCount.js  ##############################################

wget -O towerCount.js "http://xxurl/wiki/page.json?pageid=xx" 2>/dev/null




##擷取id、title、url,並顯示在頁面

cat towerCount.js |jq . |grep -E "id|title|url"

##擷取tower內容,並寫入到檔案

cat  towerCount.js |jq .data.content |sed ‘s#<p>\|<br />#\n#g‘|sed ‘s#&nbsp;\|</p>\|"\|style=\color##g‘|sed ‘/^$/d‘ > towerContent.txt


##對tower內容,進行條件輸出


while  getopts "n:d:ah"   arg

do

        case    $arg in

                    n)

                        head -n $OPTARG towerContent.txt

                        ;;

                    d)

                        head -n1 towerContent.txt;cat towerContent.txt|grep $OPTARG

                        ;;     

                    a)

                        cat towerContent.txt

                        ;;

                    h)

                        echo "sh $0 -n num(行數), 顯示最近n天的記錄 sh $0 -n 2"

                        echo "sh $0 -d date 顯示這天的記錄 example: sh $0 -d 2017-8-01"

                        echo "sh $0 -a  顯示所有的記錄     example: sh $0 -a"

                        echo "sh $0 -h  顯示協助           example: sh $0 -h"

                        ;; 

                    ?)

                        echo "unkonw argument; sh $0 -n num(行數) or -d 2017-08-12 or  -a"

                        ;;

        esac


done


擷取wiki某網頁資訊shell即擷取wiki子目錄資訊-shell

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.