curl -o, --output

-o, --output


常规操作一:把一个请求的响应写入单个文件中

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


常规操作二:把多个请求的响应写入多个文件中(单个集合变量)

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下执行{}需要转义,即\{.....\}
image.png


常规操作三:把多个请求的响应写入多个文件中(单个数组变量)

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

image.png


常规操作三:把多个请求的响应写入多个文件(多个集合、多个数组变量)

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


  1. Write output to instead of stdout.
  2. If you are using {} or [] to fetch multiple documents, you can use '#' followed by a number in the 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.

你可能感兴趣的:(curl)