思路: 首先通过curl得到页面的代码,再分析代码通过sed和awk获得开奖号,再格式化输出!
脚本:
#!/bin/bash if [ "x$1" == "x" ]; then curl -o file.html http://www.cwl.gov.cn/ > /dev/null 2>&1 if [ $? -eq 0 ]; then qishu=`cat file.html|sed -n ‘/<li class=\"caizhong\">/,+13p‘|head -13 |sed -n ‘/<span>第[0-9]*期<\/span>/p‘| awk -F "[<>]" ‘{print "["$3"]"}‘` numbers=`cat file.html | sed -n ‘/<span[^0-9]*>[0-9]\{0,2\}<\/span>$/p‘ | sed -n ‘1,7p‘ | awk -F "[<>]" ‘{print $3}‘ | awk ‘{ORS=" ";print $0}END{printf "\n"}‘` awk ‘BEGIN{print "双色球开奖查询:";print "===================================";}‘ echo -n $qishu arr=($numbers) for ((i=0; i < ${#arr[@]};++i)) do if [ "$i" == "6" ]; then echo -n -e "\e[0;34m ${arr[i]}\e[m" else echo -n -e "\e[0;31m ${arr[i]}\e[m" fi done printf "\n" awk ‘BEGIN{print "==================================="}‘ exit 0 else echo "Download file fail,Please check you network!" exit 1 fi else echo "Usage: sh `basename $0` " exit 1 fi
运行结果:
时间: 2024-12-09 04:34:44