从 HTML 文档中提取 IP 地址 [英] Extract IP address from HTML document
本文介绍了从 HTML 文档中提取 IP 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何打印下一行的 IP 地址 (86.23.215.130)?整个文件(未显示)是来自 wget(因此是 HTML)的标准输出.听起来很简单,但我没有做到.
How can I print the IP address (86.23.215.130) of the following line? The entire file (not shown) is the stdout from a wget (hence HTML). Sounds easy, but I didn't manage.
...
<tr><td align=center colspan=3 bgcolor="D0D0D0"><font face="Arial, Monospace" size=+3>86.23.215.130</font></td></tr>
...
谢谢
推荐答案
为什么使用 sed?我相信 grep 好多了:
Why sed? I believe grep is much better:
grep -iohP '(?<=\x3e)([0-9]+\.){3}[0-9]+(?=\x3c)' file
其中 \x3e 表示 > 而 \x3c 表示 <(ascii 十六进制代码)
where \x3e means > and \x3c means < (ascii hex code)
虽然 sed 可以做到这一点,但不推荐:
Although sed can do this, but it's not recommended:
sed -rn 's/.*\x3e(([0-9]+\.){3}[0-9]+)\x3c.*/\1/p' file
感谢 Sternad 先生,我改进了一点.
Thanks to Mr. Sternad, I improved this a little bit.
这篇关于从 HTML 文档中提取 IP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文