1

我需要在 Bash 脚本中获取一些超引用。

以下命令使用curlandxmllint读取hrefHTML 页面的所有属性:

curl --silent -L google.com | xmllint --html --xpath '//a/@href' - 

但我只需要属性的值。可以使用string()函数选择属性的值。但是如果我使用它,我只会得到属性列表的第一个元素:

curl --silent -L google.com | xmllint --html --xpath 'string(//a/@href)' - 

如何将string()函数应用于每个属性?

4

1 回答 1

0

You could do (notice the difference in the XPath expression):

curl --silent -L google.com | xmllint --html --xpath '//a/@*'

and then add another pipe to send the output to sed, filtering out the attribute names to get the values you want. But this is a sort of odd way to extract stuff from a document.

于 2014-11-14T20:29:31.050 回答