【发布时间】:2016-04-21 00:52:02
【问题描述】:
我已经创建了一个由几个 shell 脚本组成的小程序,它们一起工作,几乎完成了 一切似乎都很好,除了我不太确定该怎么做的一件事。 我需要,才能完成这个项目......
似乎有很多路线可以走,但我就是无法到达那里......
我有一些 curl 结果,其中包含许多未使用的数据,包括不同的链接,并且在所有数据之间有一堆相似的链接 我只需要获取(进入变量)最高数字的链接(没有始终相同的文本)
the links are all similar, and have this structure:
<a href="https://always/same/link/same-name_19.html">always same text</a>
<a href="https://always/same/link/same-name_18.html">always same text</a>
<a href="https://always/same/link/same-name_17.html">always same text</a>
我在想类似的事情;
content="$(curl -s "$url/$param")"
linksArray= get from $content all links that are in the href section of the links
that contain "always same text"
declare highestnumber;
for file in $linksArray
do
href=${1##*/}
fullname=${href%.html}
OIFS="$IFS"
IFS='_'
read -a nameparts <<< "${fullname}"
IFS="$OIFS"
if ${nameparts[1]} > $highestnumber;
then
highestnumber=${nameparts[1]}
fi
done
echo ${nameparts[1]}_${highestnumber}.html
结果:
https://always/same/link/unique-name_19.html
这只是我的猜测,任何可以从 bash 脚本运行的工作代码都可以... 谢谢...
更新
我找到this nice program,很容易安装:
# 64bit version
wget -O xidel/xidel_0.9-1_amd64.deb https://sourceforge.net/projects/videlibri/files/Xidel/Xidel%200.9/xidel_0.9-1_amd64.deb/download
apt-get -y install libopenssl
apt-get -y install libssl-dev
apt-get -y install libcrypto++9
dpkg -i xidel/xidel_0.9-1_amd64.deb
它看起来棒极了,但我不确定如何根据我的需要调整它。
基于该链接和以下答案,我想可能的解决方案是..
【问题讨论】:
-
为什么不像
thelatest=$(grep -o 'https:.*[.]html' < <(curl -s "$url/$param") | sort | tail -n1)这样简单?您可以根据需要调整grep正则表达式的特异性。