- A+
所属分类:应用
之前张耀老师的网页脚本由于51cto升级,课程列表页面改用javascript失效了
笔者发现视频课程页面右边的列表都为静态化后的视频课程地址,遂将老师初始版本的脚本进行了修改,在对视频课程页面使用时结果正常,遂将及修改后的脚本和部分注释发上来供大家研究
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | [root@m01 scripts]# cat html_to_table.sh #!/bin/bash # oldboy linux training # 2016-11-13 # 基于老男孩linux21期学员张耀开发脚本 # EduFile=/tmp/edu.html #process temp file1 EduFile2=/tmp/edu2.html #process 2 Url="$*" # Check for given parameters [ $# -eq 0 ] && { echo "USAGE: /bin/sh $0 http://...." exit 1 } # Judge url is ok? curl -I $Url &>/dev/null [ $? -ne 0 ] &&{ echo "Bad url,Please check it" exit 1 } # Defined get pagenum and CourseId Functions # Defined get pagenum and CourseId Functions #function getnum(){ # curl -s $Url>$EduFile # grep '"pagesGoEnd"' $EduFile &>/dev/null # if [ $? -eq 0 ] # then # num=`sed -rn 's#.*page=([0-9].*)" class="pagesGoEnd".*$#\1#gp' $EduFile` # else # num=`sed -rn 's|.*page=([0-9].*)#" class="pagesNum".*$|\1|gp' $EduFile` # fi # pagenum=${num:-1} # CourseId=`echo $Url|awk -F "[-.]" '{print $4}'` #} # Defined curl html Functions #function Curl(){ # getnum # for i in `seq $pagenum` # do # curl "http://edu.51cto.com/index.php?do=course&m=lessions&course_id=$CourseId&page=$i" 1>>$EduFile 2>/dev/null # done #} #分段没了,原函数保留,视频页抓一遍就好 function Curl(){ curl "$*" 1>>$EduFile 2>/dev/null } # Defined Create table Functions function table(){ sum="" index=1 sed -rn '/lesson/ s#<.*(<a href=")(.*)#\1http://edu.51cto.com\2#gp' $EduFile > $EduFile2 while read line do sum=$sum"<tr><th width="40" scope="row">$index</th><td width="520">$line</td>" ((index++)) done <$EduFile2 } # Defined Create html Functions function html(){ cat >/tmp/oldboy.html<<-END <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>test</title> </head> <body> <table width="560" border="1"> $sum </table> </body> </html> END } function main(){ Curl table html } main |

我的微信公众号
我的微信公众号扫一扫