我有一个文本文档,它包含了一堆这样格式的url:

URL = "sitehere.com"

我要做的是运行curl -K myfile.txt,并将curl返回的响应输出保存到一个文件中。

我该怎么做呢?


当前回答

有点晚了,但我想他们想要的是:

curl -K myfile.txt --trace-ascii output.txt

其他回答

curl -K myconfig.txt -o output.txt 

写入在指定文件中接收到的第一个输出(如果存在旧输出则覆盖)。

curl -K myconfig.txt >> output.txt

将收到的所有输出追加到指定文件。

备注:-K为可选参数。

对于单个文件,您可以使用-O而不是-O filename来使用URL路径的最后一段作为文件名。例子:

curl http://example.com/folder/big-file.iso -O

将结果保存到名为big-file的新文件中。Iso在当前文件夹。通过这种方式,它的工作原理与wget类似,但允许您指定使用wget时不可用的其他curl选项。

对于那些想要在剪贴板中复制cURL输出而不是输出到文件的人,可以在cURL命令后使用管道|来使用pbcopy。

示例:curl https://www.google.com/robots.txt | pbcopy。这将从给定的URL复制所有内容到剪贴板。

Linux版本:curl https://www.google.com/robots.txt | xclip

Windows版本:curl https://www.google.com/robots.txt |剪辑

有几个选项可以将curl输出到文件中

 # saves it to myfile.txt
curl http://www.example.com/data.txt -o myfile.txt

# The #1 will get substituted with the url, so the filename contains the url
curl http://www.example.com/data.txt -o "file_#1.txt" 

# saves to data.txt, the filename extracted from the URL
curl http://www.example.com/data.txt -O 

# saves to filename determined by the Content-Disposition header sent by the server.
curl http://www.example.com/data.txt -O -J 

有点晚了,但我想他们想要的是:

curl -K myfile.txt --trace-ascii output.txt