--############################################################
--curl 命令
--Linux下json的命令行工具 --jq
--############################################################
#jq的安装
[root@localhost ~]# -bash: jq: 未找到命令
-bash: -bash:: 未找到命令
[root@localhost ~]# yum -y install jq
已加载插件:fastestmirror
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
updates/7/x86_64/primary_db | 7.1 MB 00:00:00
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
没有可用软件包 jq。
错误:无须任何处理
#安装 EPEL源
[root@localhost ~]# yum install epel-release
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 epel-release.noarch.0.7-11 将被 安装
--> 解决依赖关系完成
依赖关系解决
===========================================================================================================================================================
Package 架构 版本 源 大小
===========================================================================================================================================================
正在安装:
epel-release noarch 7-11 extras 15 k
事务概要
===========================================================================================================================================================
安装 1 软件包
总下载量:15 k
安装大小:24 k
Is this ok [y/d/N]: y
Is this ok [y/d/N]: y
Downloading packages:
epel-release-7-11.noarch.rpm | 15 kB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : epel-release-7-11.noarch 1/1
验证中 : epel-release-7-11.noarch 1/1
已安装:
epel-release.noarch 0:7-11
完毕!
[root@localhost ~]#
#安装完EPEL源后,可以查看下jq包是否存在:
[root@localhost ~]# yum list jq
已加载插件:fastestmirror
base | 3.6 kB 00:00:00
One of the configured repositories failed (未知),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:
1. Contact the upstream for the repository and get them to fix the problem.
2. Reconfigure the baseurl/etc. for the repository, to point to a working
upstream. This is most often useful if you are using a newer
distribution release than is supported by the repository (and the
packages for the previous distribution release still work).
3. Disable the repository, so yum won't use it by default. Yum will then
just ignore the repository until you permanently enable it again or use
--enablerepo for temporary usage:
yum-config-manager --disable
4. Configure the failing repository to be skipped, if it is unavailable.
Note that yum will try to contact the repo. when it runs most commands,
so will have to try and fail each time (and thus. yum will be be much
slower). If it is a very temporary problem though, this is often a nice
compromise:
yum-config-manager --save --setopt=
Cannot retrieve metalink for repository: epel/x86_64. Please verify its path and try again
#对epel.repo 配置文件进行修改,注释掉 baseur和 metalink
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ll
总用量 48
-rw-r--r--. 1 root root 1664 11月 23 23:08 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 11月 23 23:08 CentOS-CR.repo
-rw-r--r--. 1 root root 649 11月 23 23:08 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 11月 23 23:08 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 11月 23 23:08 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 11月 23 23:08 CentOS-Sources.repo
-rw-r--r--. 1 root root 8515 11月 23 23:08 CentOS-Vault.repo
-rw-r--r--. 1 root root 616 11月 23 23:08 CentOS-x86_64-kernel.repo
-rw-r--r--. 1 root root 951 10月 3 2017 epel.repo
-rw-r--r--. 1 root root 1050 10月 3 2017 epel-testing.repo
[root@localhost yum.repos.d]# vi epel.repo
[root@localhost yum.repos.d]# cat epel.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch/debug
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/7/SRPMS
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
[root@localhost yum.repos.d]#
#/etc/resolv.conf 文件中增加两行:(主要作用:网络配置,可以联通外网)
----------------------------------------
nameserver 8.8.8.8
nameserver 114.114.114.114
----------------------------------------
[root@localhost etc]# vi resolv.conf
[root@localhost etc]# cat resolv.conf
# Generated by NetworkManager
search localdomain
nameserver 192.168.27.2
nameserver 8.8.8.8
nameserver 114.114.114.114
[root@localhost etc]#
#centos7 重启网络服务
systemctl restart network.service
--epel.repo 配置文件的修改----
--vi epel.repo
--可以先尝试yum remove epel-release 排除epel的影响
--应为我之前确实安装了这个包---
--
#安装jq的源码包:https://stedolan.github.io/jq/download/
----------安装 jq 1.6---------------------------------------------------------------------------
From source on Linux, OS X, Cygwin, and other POSIX-like operating systems
Source tarball for jq 1.6
Source tarball for jq 1.5
You can build it using the usual ./configure && make && sudo make install rigmarole.
-------------------------------------------------------------------------------------------------
#上传到服务器
[root@localhost ~]# ll
总用量 3616
-rw-------. 1 root root 1148 1月 17 22:11 anaconda-ks.cfg
-rw-r--r--. 1 root root 12537 2月 22 2019 ez_setup.py
-rw-r--r--. 1 root root 1750584 4月 18 18:51 jq-1.6.tar.gz
drwxr-xr-x. 7 501 games 4096 2月 8 23:30 pip-9.0.1
-rw-r--r--. 1 root root 1197370 2月 27 2020 pip-9.0.1.tar.gz
drwxr-xr-x. 4 root root 60 2月 15 16:21 pytest_test
-rw-r--r--. 1 root root 702770 2月 8 23:22 setuptools-33.1.1.zip
drwxr-xr-x. 2 root root 38 2月 8 22:58 test
drwxr-xr-x. 2 root root 27 1月 18 02:30 test_2021
-rw-r--r--. 1 root root 123 1月 18 01:47 test2.sh
-rwxr-xr-x. 1 root root 336 1月 18 02:29 test3.sh
-rw-r--r--. 1 root root 112 1月 18 02:04 test4.sh
-rw-r--r--. 1 root root 96 1月 18 01:33 test.sh
-rw-r--r--. 1 root root 32 1月 18 01:00 test.txt
drwxr-xr-x. 6 root root 87 2月 10 23:11 venv
#进行解压安装
[root@localhost ~]# tar -zvxf jq-1.6.tar.gz
#查看解压包的目录
[root@localhost ~]# ll
总用量 3620
-rw-------. 1 root root 1148 1月 17 22:11 anaconda-ks.cfg
-rw-r--r--. 1 root root 12537 2月 22 2019 ez_setup.py
drwxr-xr-x. 13 501 games 4096 11月 2 2018 jq-1.6
-rw-r--r--. 1 root root 1750584 4月 18 18:51 jq-1.6.tar.gz
drwxr-xr-x. 7 501 games 4096 2月 8 23:30 pip-9.0.1
-rw-r--r--. 1 root root 1197370 2月 27 2020 pip-9.0.1.tar.gz
drwxr-xr-x. 4 root root 60 2月 15 16:21 pytest_test
-rw-r--r--. 1 root root 702770 2月 8 23:22 setuptools-33.1.1.zip
drwxr-xr-x. 2 root root 38 2月 8 22:58 test
drwxr-xr-x. 2 root root 27 1月 18 02:30 test_2021
-rw-r--r--. 1 root root 123 1月 18 01:47 test2.sh
-rwxr-xr-x. 1 root root 336 1月 18 02:29 test3.sh
-rw-r--r--. 1 root root 112 1月 18 02:04 test4.sh
-rw-r--r--. 1 root root 96 1月 18 01:33 test.sh
-rw-r--r--. 1 root root 32 1月 18 01:00 test.txt
drwxr-xr-x. 6 root root 87 2月 10 23:11 venv
[root@localhost ~]#
#进入目录,进行make 编译安装
[root@localhost ~]# cd jq-1.6
[root@localhost jq-1.6]# ll
总用量 940
-rw-r--r--. 1 501 games 46174 11月 2 2018 aclocal.m4
-rw-r--r--. 1 501 games 2323 11月 2 2018 appveyor.yml
-rw-r--r--. 1 501 games 4180 11月 2 2018 AUTHORS
drwxr-xr-x. 2 501 games 4096 4月 18 18:55 autom4te.cache
drwxr-xr-x. 2 501 games 6 11月 2 2018 build
-rw-r--r--. 1 501 games 33283 11月 2 2018 ChangeLog
-rwxr-xr-x. 1 501 games 2727 11月 2 2018 compile-ios.sh
drwxr-xr-x. 3 501 games 4096 4月 18 18:55 config
-rwxr-xr-x. 1 501 games 622024 11月 2 2018 configure
-rw-r--r--. 1 501 games 9307 11月 2 2018 configure.ac
-rw-r--r--. 1 501 games 2940 11月 2 2018 COPYING
-rw-r--r--. 1 501 games 1539 11月 2 2018 Dockerfile
drwxr-xr-x. 5 501 games 4096 4月 18 18:55 docs
-rw-r--r--. 1 501 games 100874 11月 2 2018 jq.1.prebuilt
-rw-r--r--. 1 501 games 1451 11月 2 2018 jq.spec
-rw-r--r--. 1 501 games 421 11月 2 2018 KEYS
drwxr-xr-x. 2 501 games 65 4月 18 18:55 m4
-rw-r--r--. 1 501 games 6544 11月 2 2018 Makefile.am
-rw-r--r--. 1 501 games 66196 11月 2 2018 Makefile.in
drwxr-xr-x. 3 501 games 22 4月 18 18:55 modules
-rw-r--r--. 1 501 games 2344 11月 2 2018 NEWS
lrwxrwxrwx. 1 501 games 9 11月 2 2018 README -> README.md
-rw-r--r--. 1 501 games 3045 11月 2 2018 README.md
drwxr-xr-x. 2 501 games 85 4月 18 18:55 scripts
drwxr-xr-x. 8 501 games 99 4月 18 18:55 sig
drwxr-xr-x. 2 501 games 4096 4月 18 18:55 src
drwxr-xr-x. 4 501 games 4096 11月 2 2018 tests
#进行make 编译安装
[root@localhost jq-1.6]# ./configure && make && sudo make install
#安装jq1.5
---------------------------------------------------------------------------------
jq 1.6 一直安装失败,make 编译一直提示:make: *** 没有规则可以创建 。停止,离开目录
改了镜像源的配置文件,按照网上老哥们的提示弄了,还是没有成功,下载几个镜像源地址也不行
下载不了(刚开始一直yum安装,所以实在不行,就想换个镜像源地址,已经搞了一个晚上,心累~~~)
心想,我是源码安装,make 编译不过(在这期间,我也按照老哥们说的,修改了下makefile文件)
会不会是包的问题,因为我看老哥们安装的都是jq1.5的,我是看了Github地址里有一个最新的
所以就安装了1.6的,最后本着百折不挠的精神,遇到问题一个一个的解决,逢山开路遇水搭桥
相信自己终于有一天会成为nb的存在,然后试了一下jq-1.5的包,安装,编译,一气呵成
好了,记录一下,自己的心路历程
---------------------------------------------------------------------------------
[root@localhost jq-1.5]# make install
GEN version.h
make install-am
make[1]: 进入目录“/root/jq-1.5”
GEN version.h
CC main.o
CCLD jq
make[2]: 进入目录“/root/jq-1.5”
GEN version.h
CC main.o
CCLD jq
/usr/bin/mkdir -p '/usr/local/lib'
/bin/sh ./libtool --mode=install /usr/bin/install -c libjq.la '/usr/local/lib'
libtool: install: /usr/bin/install -c .libs/libjq.so.1.0.4 /usr/local/lib/libjq.so.1.0.4
libtool: install: (cd /usr/local/lib && { ln -s -f libjq.so.1.0.4 libjq.so.1 || { rm -f libjq.so.1 && ln -s libjq.so.1.0.4 libjq.so.1; }; })
libtool: install: (cd /usr/local/lib && { ln -s -f libjq.so.1.0.4 libjq.so || { rm -f libjq.so && ln -s libjq.so.1.0.4 libjq.so; }; })
libtool: install: /usr/bin/install -c .libs/libjq.lai /usr/local/lib/libjq.la
libtool: install: /usr/bin/install -c .libs/libjq.a /usr/local/lib/libjq.a
libtool: install: chmod 644 /usr/local/lib/libjq.a
libtool: install: ranlib /usr/local/lib/libjq.a
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/sbin" ldconfig -n /usr/local/lib
----------------------------------------------------------------------
Libraries have been installed in:
/usr/local/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/usr/bin/mkdir -p '/usr/local/bin'
/bin/sh ./libtool --mode=install /usr/bin/install -c jq '/usr/local/bin'
libtool: install: /usr/bin/install -c jq /usr/local/bin/jq
/usr/bin/mkdir -p '/usr/local/share/doc/jq'
/usr/bin/install -c -m 644 README.md COPYING AUTHORS README '/usr/local/share/doc/jq'
/usr/bin/mkdir -p '/usr/local/include'
/usr/bin/install -c -m 644 jv.h jq.h '/usr/local/include'
/usr/bin/mkdir -p '/usr/local/share/man/man1'
/usr/bin/install -c -m 644 jq.1 '/usr/local/share/man/man1'
make[2]: 离开目录“/root/jq-1.5”
make[1]: 离开目录“/root/jq-1.5”
[root@localhost jq-1.5]#
--------------------------------------------------------------------
#jq命令查看是否安装成功,以及常用的命令
[root@localhost ~]# jq
jq - commandline JSON processor [version 1.5]
Usage: jq [options]
jq is a tool for processing JSON inputs, applying the
given filter to its JSON text inputs and producing the
filter's results as JSON on standard output.
The simplest filter is ., which is the identity filter,
copying jq's input to its output unmodified (except for
formatting).
For more advanced filters see the jq(1) manpage ("man jq")
and/or https://stedolan.github.io/jq
Some of the options include:
-c compact instead of pretty-printed output;
-n use `null` as the single input value;
-e set the exit status code based on the output;
-s read (slurp) all inputs into an array; apply filter to it;
-r output raw strings, not JSON texts;
-R read raw strings, not JSON texts;
-C colorize JSON;
-M monochrome (don't colorize JSON);
-S sort keys of objects on output;
--tab use tabs for indentation;
--arg a v set variable $a to value
--argjson a v set variable $a to JSON value
--slurpfile a f set variable $a to an array of JSON texts read from
See the manpage for more options.
[root@localhost ~]#
#输入curl命令进行请求,jq命令,格式化响应
[root@localhost ~]# curl 'https://xueqiu.com/query/v1/search/web/stock.json?q=sogo&size=3&page=1' \
> -H 'Connection: keep-alive' \
> -H 'Accept: application/json, text/plain, */*' \
> -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36' \
> -H 'elastic-apm-traceparent: 00-777069c82afea6a28c74c5ca3236c907-338a4c75742d77ca-00' \
> -H 'Sec-Fetch-Site: same-origin' \
> -H 'Sec-Fetch-Mode: cors' \
> -H 'Sec-Fetch-Dest: empty' \
> -H 'Referer: https://xueqiu.com/k?q=sogo' \
> -H 'Accept-Language: zh-CN,zh;q=0.9' \
> -H 'Cookie: acw_tc=2760820116187973259076791e459312932729438bc93409589f873896b67c; device_id=dc7961cafb46188a75505643f0c92086; xq_a_token=520e7bca78673752ed71e19b8820b5eb854123af; xqat=520e7bca78673752ed71e19b8820b5eb854123af; xq_r_token=598dda88240ff69f663261a3bf4ca3d9f9700cc0; xq_id_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1aWQiOi0xLCJpc3MiOiJ1YyIsImV4cCI6MTYyMTIxOTc0OSwiY3RtIjoxNjE4Nzk3MzU0MTIxLCJjaWQiOiJkOWQwbjRBWnVwIn0.DotCf1VwDZBMbIww17Qge-OPqlxuqbNFSxR5bKHkV7vCVKX3AiMPAVhMAeOrsO2Q1Ml5xlqBw0OANVcOEEkK_i7pDCFhgN6Pd611PipoTWS4d_ez-bQNoDQlz-6LhQoUQIZpnZJAPSgJf2nBvvDPc-LbgRNpEJz1wX8aQnIPt0l3l9xdG_UGjoFjqZxOHnVA1a23bKZ-VkzDAR29D8v70hbK6o1dbKeSsq6OSk-Y0lnXX5JkY-FHKGIP5478doA8h-4nCHwzad0L59u-7o-Ktb164U69vvvRsg0-FRBvAlI4IijeKgwE7J_9Y0nJh041Bi6-83r9-L9x9-hIGRXcsw; u=301618797362791; Hm_lvt_1db88642e346389874251b5a1eded6e3=1618797331,1618797366; Hm_lpvt_1db88642e346389874251b5a1eded6e3=1618797366' \
> --compressed | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 181 100 181 0 0 577 0 --:--:-- --:--:-- --:--:-- 578
{
"count": 1,
"list": [
{
"code": "SOGO",
"current": "8.49",
"name": "搜狗",
"percentage": -0.4689,
"type": 0
}
],
"maxPage": 1,
"page": 1,
"query_id": 1383962982429671400,
"recommend_cards": [],
"size": 1
}