如果您已经使用过 Xidel,您通常需要定位具有特定类别的节点。为了更容易做到这一点,我想创建has-class("class")
一个函数作为表达式的别名:
contains(concat(" ", normalize-space(@class), " "), " class ")
。
例子:
$ e-xidel.sh example.com '//article/p//img[has-class("wp-image")]'
e-xidel.sh 包含以下代码:
#!/bin/bash
echo -e "$(tput setaf 2) Checking... $(tput sgr0)"
path=$1
expression=$2
# expression = '//article/p//img[has-class("wp-image")]'
# Regex to replace every * has-class("class") * by * contains(concat(" ", normalize-space(@class), " "), " class ") *
# ...
# ...
# expression = '//article/p//img[contains(concat(" ", normalize-space(@class), " "), " wp-image ")]'
xoutput=$(xidel $path --printed-node-format=html --output-declaration= -e "$expression")
echo -e "$(tput setaf 1) $xoutput $(tput sgr0)"