0
什麼是正則表達式在這個標籤中查找文本「這是標題」?使用Grep,Sed或Awk。使用Bash查找H1文本
代碼示例:
<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>
,我只需要 「這是標題」 的一部分。
對於一般情況,您需要使用HTML解析器。 – pizza
如果我需要使用HTML解析器,我會的。但我需要bash =) – Tux
'grep'在這裏完全沒有問題,因爲它一次只能在一條線上運行。 Sed或awk可以處理簡單的情況,但爲了充分處理結構化數據,您確實需要使用可以處理結構的工具。見例如http://stackoverflow.com/questions/590747/using-regular-expressions-to-parse-html-why-not – tripleee