如何捕获Curl输出到文件?

本文翻译自:How to capture Curl output to a file?

I have a text document that contains a bunch of URLs in this format: 我有一个文本文档,其中包含以这种格式的一堆URL:

URL = "sitehere.com"

What I'm looking to do is to run curl -K myfile.txt , and get the output of the response Curl returns, into a file. 我要做的是运行curl -K myfile.txt ,并将响应Curl的输出返回到文件中。

How can I do this? 我怎样才能做到这一点?


#1楼

参考:https://stackoom.com/question/vd75/如何捕获Curl输出到文件


#2楼

curl -K myconfig.txt -o output.txt 

Writes the first output received in the file you specify (overwrites if an old one exists). 写入您指定的文件中收到的第一个输出(如果存在旧的输出则覆盖)。

curl -K myconfig.txt >> output.txt

Appends all output you receive to the specified file. 将您收到的所有输出追加到指定的文件中。


#3楼

For a single file you can use -O instead of -o filename to use the last segment of the URL path as the filename. 对于单个文件,您可以使用-O而不是-o filename将URL路径的最后一段用作文件名。 Example: 例:

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

will save the results to a new file named big-file.iso in the current folder. 将结果保存到当前文件夹中名为big-file.iso的新文件。 In this way it works similar to wget but allows you to specify other curl options that are not available when using wget. 这样它的工作方式类似于wget,但允许您指定使用wget时不可用的其他curl选项


#4楼

For those of you want to copy the cURL output in the clipboard instead of outputting to a file, you can use pbcopy by using the pipe | 对于那些想要在剪贴板中复制cURL输出而不是输出到文件的人,可以使用管道来使用pbcopy | after the cURL command. 在cURL命令之后。

Example: curl https://www.google.com/robots.txt | pbcopy 示例: curl https://www.google.com/robots.txt | pbcopy curl https://www.google.com/robots.txt | pbcopy . curl https://www.google.com/robots.txt | pbcopy This will copy all the content from the given URL to your clipboard. 这会将给定URL中的所有内容复制到剪贴板。


#5楼

There are several options to make curl output to a file 有几个选项可以将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 
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值