curl
- curl is a tool to transfer data from or to a server
- support protocols
- DICT,FILE,FTP,FTPS,GOPHER,HTTP,HTTPS,IMAP
- without user interaction
proxy support
- curl -x 127.0.0.1:8888 https://www.baidu.com
get
- -G:使用 get 请求
- -d:指定请求数据
- curl https://www.baidu.com
- curl -G https://www.baidu.com
- curl -X GET https://www.baidu.com
post
- -d:指定 post 请求
- curl -d 'login=1234' https://www.baidu.com
- curl -X POST https://www.baidu.com
other
- 保存响应内容
- curl -o tmp.html https://www.baidu.com
- 输出通信的整个过程
- curl -v https://www.baidu.com
- 不输出错误和进度信息
- curl -s https://www.baidu.com
jq
- A jq program is a filter
- it takes an input, and produces an output
- https://stedolan.github.io/jq/
using
- .格式优化
- echo '{"a":11,"b":12}' | jq '.'
- it takes an input, and produces an output
常用方法
- 内容提取
- echo '{"foo":42,"bar":"less interesting data"}' | jq .foo
- 从数组中提取单个数据
- echo '[{"a":1,"b":2},{"c":3,"d":4}]' | jq .[0]
- 从数组中提取所有数据
- echo '[{"a":1,"b":2},{"c":3,"d":4}]' | jq .[]
- 过滤多个值
- echo '[{"a":1,"b":2},{"c":3,"d":4}]' | jq .[0,1]
- 数据重组成数组
- echo '{"a":1,"b":2,"c":3,"d":4}' | jq '[.a,.b]'
- 数据重组成对象
- echo '{"a":1,"b":2,"c":3,"d":4}' | jq '{"tmp":.b}'