挑战shell:下载Qt官网范例
Tofloor
poster avatar
海天鹰
deepin
2018-03-21 06:44
Author
打开网页一个个文件复制太麻烦了。
shell实在是太强大,正则实在是太晕,资料翻烂,搞了几天,最后回头看,我写的啥,自己都看不懂了。
试试吧,少年,你会有所感悟~
还有几个小问题:
1.想把*.pro文件名提取出来做目录名称,暂时失败
2.&替换&失败
3.官网的Qt比商店的Qt版本高,有些缺文件,导致源码运行不了。

#清屏
printf "\033c"
URL=http://doc.qt.io/qt-5/qtwidgets-itemviews-frozencolumn-example.html
domain=${URL%/*}"/"
#echo $domain
#创建缓存文件
HTML=`mktemp`
#下载到缓存文件
wget -q $URL -O $HTML
files=`sed -n '/

Files:<\/p>/,/<\/ul>/p' $HTML`
filename=($(echo "$files" | sed -n '/\|.*##g' | sed 's#.*/##g'))
echo "${filename[@]}" | sed 's#\.pro.*##g' | sed 's#.*\s+##g'
#echo $dir
fileURL=($(echo "$files" | sed -n '/.*$//g'))
#:< for i in "${!fileURL[@]}";
do
        echo ${fileURL[$i]} "->" ${filename[$i]}
        wget -q ${fileURL[$i]} -O $HTML       
        contents=`sed -n '/

 ${filename[$i]}
done
#!

Reply Favorite View the author
All Replies
avatar
南浦月
deepin
2018-03-21 21:11
#1
shell 的正则不是这样玩儿的啊……
Reply View the author
avatar
南浦月
deepin
2018-03-21 22:18
#2
本帖最后由 nanpuyue 于 2018-3-21 14:40 编辑
  1. sudo apt install w3m
Copy the Code
  1. #!/bin/bash
  2. # file: dl_qt_example.sh
  3. # date: 2018-03-21
  4. # license: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt
  5. # author: nanpuyue https://blog.nanpuyue.com

  6. URL="http://doc.qt.io/qt-5/qtwidgets-itemviews-frozencolumn-example.html"

  7. BASE_URL=${URL%/*}
  8. curl -so- "$URL"|\
  9.     sed -n '/^

    Files\:/,/@@@/p'|\

  10.     grep -Po '(?<=href\=").*?(?=")'|\
  11.     while read line;do
  12.         data="$(curl -so- "$BASE_URL/$line")"
  13.         file="$(echo "$data"|grep -Po '(?<=@@@).*?(?=\s)')"
  14.         mkdir -p "${file%/*}" || true
  15.         echo "$data"|\
  16.             sed -n '/\$\$\$/,/@@@/p'|\
  17.             w3m -dump -T text/html|\
  18.             grep -v '^\['|\
  19.             cat > "$file"
  20.        echo "file: $file downloaded."
  21.     done
Copy the Code


Reply View the author
avatar
rekols
deepin
2018-03-21 23:02
#3
不清真啊
Reply View the author