比如说,我们有一个密码:
xidel -s https://www.example.com -e '(//span[@class="number"])'产出如下:
111111
222222
333333我能在下面做这个吗?
for ((n=1;n<=3;n++))
do
a=$(xidel -s https://www.example.com -e '(//span[@class="number"]) [$n]')
b=$a+1
echo $b
done我希望它能打印出3个经过编辑的数字,像这样:
111112
222223
333334下载3次网页可能有点荒谬,但这里的原因是使用ForLoop逐个处理输出的每个值。
发布于 2020-06-16 22:31:05
xidel完全支持XPath/XQuery3.0(对XPathXQuery3.1的支持正在开发中),因此您可以使用它提供的所有特性和过滤器。
我可以推荐以下网站:
如果没有"Minimal, Reproducible Example“,我将把上面提到的输出放在一个序列中,并向您展示一些示例。
xidel -se 'let $a:=(111111,222222,333333) return $a ! (. + 1)'
#or
xidel -se 'for $x in (111111,222222,333333) return $x + 1'
111112
222223
333334xidel -se 'let $a:=("a abc","a sdf","a wef","a vda","a gdr") return $a ! substring-after(.,"a ")'
#or
xidel -se 'let $a:=("a abc","a sdf","a wef","a vda","a gdr") return $a ! replace(.,"a ","")'
#or
xidel -se 'for $x in ("a abc","a sdf","a wef","a vda","a gdr") return substring-after($x,"a ")'
#or
xidel -se 'for $x in ("a abc","a sdf","a wef","a vda","a gdr") return replace($x,"a ","")'
abc
sdf
wef
vda
gdr发布于 2020-06-16 07:13:30
示例代码:
$ aa=$(xidel -se '//span[@class="random"]' 'https://www.example.com')
$ echo $aa让我们说,xidel的结果如下:
a abc
a sdf
a wef
a vda
a gdrand...lets说,在这个例子中,我们希望从列表中的每个单词中删除所有的a,而不仅仅是排除a。
我们可以使用这样的For Loop公式:
#"a " is the one we want to remove, so make variable for this prefix
a="a "
for ((n=-1;n>=-5;n--))
do
#process the extraction by selecting which line first
bb=$(echo "$aa" | head $n | tail -1)
#then remove the prefix after that
bb=${aa/#$a}
echo $bb
done这将打印:
abc
sdf
wef
vda
gdr奖金
#"a " is the one we want to remove, so make variable for this prefix
a="a "
for ((n=-1;n>=-5;n--))
do
#process the extraction by selecting which line first
bb=$(echo "$aa" | head $n | tail -1)
#then remove the prefix after that
bb=${aa/#$a}
#echo everything except 2nd line
if [ $n != -2 ] ; then
echo $bb
fi
done这将打印:
abc
wef
vda
gdr欢迎任何其他意见。
https://stackoverflow.com/questions/62401465
复制相似问题