关于curl:curl-o-output-file

65次阅读

共计 1342 个字符,预计需要花费 4 分钟才能阅读完成。

-o, –output <file>


惯例操作一:把一个申请的响应写入单个文件中

curl www.baidu.com –output “baidu.txt”
将会把百度首页的内容放入文件 baidu.txtbaidu.txt 在执行命令的当前目录生成。


惯例操作二:把多个申请的响应写入多个文件中(单个汇合变量)

curl -v https://ai.baidu.com/ai-doc/FACE/{6k37c1nva,Yk37c1o30} –output “file_#1abc.txt”
将会把两个接口 https://ai.baidu.com/ai-doc/FACE/Okg7edktqhttps://ai.baidu.com/ai-doc/FACE/6k37c1nva 的内容别离存入 file_Okg7edktqabc.txt,file_Yk37c1o30abc.txt 文件中,大括号相当于汇合,外面的元素会替换掉指定的文件名中的 #1 字符。
留神:此命令在 linux 下执行 {} 须要本义,即 \{…..\}


惯例操作三:把多个申请的响应写入多个文件中(单个数组变量)

curl https://ai.baidu.com/ai-doc/FACE/Yk37c1o3[0-5] –output “b_#1.txt”
将会把六个接口:

  1. https://ai.baidu.com/ai-doc/FACE/Yk37c1o30
  2. https://ai.baidu.com/ai-doc/FACE/Yk37c1o32
  3. https://ai.baidu.com/ai-doc/FACE/Yk37c1o33
  4. https://ai.baidu.com/ai-doc/FACE/Yk37c1o34
  5. https://ai.baidu.com/ai-doc/FACE/Yk37c1o35
  6. https://ai.baidu.com/ai-doc/FACE/Yk37c1o36

的响应别离存入以下文件

  1. b_0.txt
  2. b_1.txt
  3. b_2.txt
  4. b_3.txt
  5. b_4.txt
  6. b_5.txt

惯例操作三:把多个申请的响应写入多个文件(多个汇合、多个数组变量)

curl http://{site,host}.baidu.{one,two}.host[1-5].sina[0-5].com -o “#1_#2_#3_#4”
请自行演示。


  1. Write output to <file> instead of stdout.
  2. If you are using {} or [] to fetch multiple documents, you can use ‘#’ followed by a number in the <file> specifier. That
    variable will be replaced with the current string for the URL being fetched. Like in:
    curl http://{one,two}.site.com -o “file_#1.txt”
    or use several variables like:
    curl http://{site,host}.host[1-5].com -o “#1_#2”
  3. You may use this option as many times as the number of URLs you have.
正文完
 0