我尝试通过curl和xmllint来解析来自url的xml输出。但是由于某种原因,xml不会解析xml,而是显示从curl得到的xml。我缺了一个布景?如果将curl操作的结果存储为一个文件,并将其用作xmllint的输入,则它将正确解析。
curl --location --header "Accept: application/rdf+xml" http://www.test.com | xmllint --format - --xpath '//title'发布于 2014-01-05 07:57:26
似乎xmllint要求-标准输入重定向位于命令的末尾。
curl --location --header "Accept: application/rdf+xml" http://www.test.com \
| xmllint --format --xpath '//title' -发布于 2020-08-04 04:10:38
更简洁
curl foo.com/somefile.xml | xmllint --format -解释:
这里我们将curl命令中的xml piping到xmllint命令中。xmllint手册页上说
$ man xmllint
> ... The xmllint program parses one or more XML files, specified on the command line as XML-FILE (or the standard input if the filename provided is - ).这就是我们执行xmllint --format -的原因,因为如果您指定-作为文件名,此命令将从标准输入中读取。附注,这里有一个关于- arg here的讨论。我个人不喜欢stdin不是默认的,但我不是作者。
https://stackoverflow.com/questions/19908777
复制相似问题