1.软文推荐

2.软文推荐

3.软文推荐

htmlq能够对 HTML 数据进行 sed 或 grep 操作。我们可以使用 htmlq 搜索、切片和过滤 HTML 数据。让我们看看如何在 Linux 或 Unix 上安装和使用这个方便的工具并处理 HTML 数据。

什么是htmlq?

htmlq类似于 jq,但用于 HTML。使用 CSS 选择器从 HTML 文件中提取部分内容。在 CSS 中,选择器用于定位我们想要设置样式的网页上的 HTML 元素。例如,我们可以使用此工具轻松提取图像或其他 URL。

安装htmlq

首先需要在系统中安装cargo然后使用cargo来安装htmlq:

[root@localhost ~]# yum -y install cargo
[root@localhost ~]# cargo install htmlq
设置可执行的路径

确保将 $HOME/.cargo/bin 添加到 PATH 变量中,以便能够使用 export 命令运行已安装的二进制文件:

[root@localhost ~]# echo 'export PATH="$PATH:$HOME/.cargo/bin"' >> ~/.bash_profile
[root@localhost ~]# . ~/.bash_profile
如何使用 htmlq 从 HTML 文件中提取内容?

下面是使用curl和htmlq的用法:

curl -s url | htmlq '#css-selector'
curl -s url2 | htmlq '.css-selector'
curl -s https://www.linuxprobe.com | htmlq --pretty '#content' | more

让我们找到页面中的所有链接。例如:

[root@localhost ~]# curl -s https://www.linuxprobe.com | htmlq --attribute href a

人性化显示HTML:

[root@localhost ~]# curl --silent https://mgdm.net | htmlq --pretty '#posts'
帮助手册

使用下面命令查看帮助页面:

[root@localhost ~]# htmlq --help
htmlq 0.3.0
Michael Maclean 
Runs CSS selectors on HTML

USAGE:
   htmlq [FLAGS] [OPTIONS] [selector]...

FLAGS:
   -B, --detect-base          Try to detect the base URL from the  tag in the document. If not found, default to
                              the value of --base, if supplied
   -h, --help                 Prints help information
   -w, --ignore-whitespace    When printing text nodes, ignore those that consist entirely of whitespace
   -p, --pretty               Pretty-print the serialised output
   -t, --text                 Output only the contents of text nodes inside selected elements
   -V, --version              Prints version information

OPTIONS:
   -a, --attribute     Only return this attribute (if present) from selected elements
   -b, --base               Use this URL as the base for links
   -f, --filename           The input file. Defaults to stdin
   -o, --output             The output file. Defaults to stdout

ARGS:
   ...    The CSS expression to select [default: html]

本文来源:www.lxlinux.net/9625.html,若引用不当,请联系修改。

相关文章 8

2

teamviewer免费版(teamviewer免费版怎么下载) 4分钟前

目录:1、TeamViewer的免费版和付费版之间有什么区别?2、teamviewer是免费的吗3、teamviewer免费版可以用多久不断线?几个小时可以吗?4、teamvie...

3

Linux系统使用yum安装MySQL详细步骤 6分钟前

详细各位小伙伴都熟悉MySQL吧,但是怎样在Linux系统中安装MySQL呢?下面我们使用yum进行一个MySQL的安装,各位小伙伴一起来看看在Linux系统中...

4

Linux系统查看tomcat版本命令 7分钟前

Tomcat 是一个小型的轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,那么在Linux系统如何查看Tomcat?本篇文...

5

腾讯云服务器配置(腾讯云服务器配置安全组) 10分钟前

目录:1、腾讯云买哪个服务器配置?2、买腾讯云服务器需要啥条件3、腾讯轻量云服务器搭建k8s环境4、腾讯云windows server2019设置服务,可用...

6

Linux系统配置DHCP具体步骤 11分钟前

随着网络化的进一步发展,人们的工作、学习和生活与网络联系越来越紧密,为了满足人们的需要,也搭建了许多不同的网络。那么网络管...

7

云立方(云立方虚拟实训平台) 14分钟前

目录:1、云立方是什么软件?能做什么?2、云立方虚拟实训平台快捷键是什么3、云立方有没有专利云立方是什么软件?能做什么? isBIM云...

8

Redhat 7使用CentOS 7的Yum网络源具体步骤 16分钟前

Redhat 7如何使用CentOS 7的Yum网络源?,CentOS几乎和redhat是一样的,所以无需担心软件包是否可安装,安装之后是否有问题,另外CentOS公司去年...