0

在这个标签中查找文本“这是标题”的正则表达式是什么?使用 Grep、Sed 或 Awk。

代码示例:

<h1 class="round title">
  <a href="/somepage">This is the title</a>
</h1>

我在上面的 h1 标签上试过这个。

curl --silent http://domain.com/index.html | grep "<h1 class=\"round title\">"

结果是:

<h1 class="round title"><a href="/somepage">This is the title</a></h1>

我只需要“这是标题”的一部分。

4

1 回答 1

1

我通过以下命令得到了它。

curl --silent http://domain.com/index.html | grep -E "<h1.*><a.*>(.*?)</a></h1>" | sed 's/.*<a.*>\(.*\)<\/a>.*/\1/'

谢谢你们。

于 2012-09-03T06:14:08.017 回答