我怎样才能提取HTML meta标签在bash / awk脚本? [英] How can I extract meta tags from HTML in a bash/awk script?

查看:269
本文介绍了我怎样才能提取HTML meta标签在bash / awk脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作的Bash脚本提取标题标签。我需要用AWK场分离有助于从HTML中提取meta标签,像这样的:

I have a working Bash script to extract title tags. I need help with an AWK field separator for extracting meta tags from HTML, like these:

<meta name="keywords" content="key1, key2, key3">

我的脚本作品中提取标题,但 META NAME 不起作用。

#!/bin/bash
for LINE in `cat htmls.txt`

do
   echo $LINE
   awk 'BEGIN{IGNORECASE=1;FS="<title>|</title>";RS=EOF} {print $2}' $LINE |
   awk '{ if (NF > 0) printf("%s\n", $0); }'
done

我想我需要一个正则表达式的解决方案。任何想法?

I guess I need a regex solution. Any ideas?

推荐答案

首先安装 XML2 如:

sudo apt-get install xml2

wget -q -O - http://www.latin.fm | xml2 | grep meta | awk -F/ '{print $NF}'


输出


Output

@property=og:title
@content=Latin FM
...

这篇关于我怎样才能提取HTML meta标签在bash / awk脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆