[英]extract text from between html tags with specific id using sed or grep
[英]Using grep to extract html from <div> container tags
我有一個頁面,其中包含不同作者的許多帖子。 我想要來自該帖子頁面的用戶 A 的帖子。
如何設置 grep 以查看作者頁面中每個帖子的 html 塊,然后將帖子的內容打印到文件中? 帖子結構類似於
<!--Begin Msg Number #####-->
[useless junk i'm not interested in here]
<span class="author vcard"><a class="url fn" href='url here'>User A</a> </span>
[more junk]
<div class='post entry-content '>
<!--cached-some date string--> Here's the text I want to extract
</div>
[more junk]
<hr />
我認為結構類似於
grep /pattern/ output file
但我是否需要明確告訴它只在
<!-- begin msg ... -->
和
<hr />
綁定帖子的標簽,還是 grep 足夠智能以自動執行此操作? 我擔心當 grep 找到用戶 A 的模式時,它會將所有帖子內容打印到一個文件中,而不僅僅是那個特定的。
如果所有帖子文本都在一行上,請嘗試
grep /(author vcard|<!--cached-)/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.