【发布时间】:2013-05-02 16:37:36
【问题描述】:
我正在尝试在 c# 中抓取整个 div 元素...
我试过div class="txt-block"\s*(.+?)(\r\n?|\n)\s*" 但它并没有完全刮掉它:(
有任何想法吗?
这是 div.. THX!
<div class="txt-block" itemprop="creator" itemscope itemtype="http://schema.org/Person">
<h4 class="inline">Writers:</h4>
<a href="/name/nm1318843/?ref_=tt_ov_wr" itemprop='url'><span class="itemprop" itemprop="name">Mark Fergus</span></a> (screenplay),
<a href="/name/nm1319757/?ref_=tt_ov_wr" itemprop='url'><span class="itemprop"
itemprop="name">Hawk Ostby</span></a> (screenplay), <a href="fullcredits?ref_=tt_ov_wr#writers" >6 more credits</a> »
</div>
【问题讨论】:
-
您真的需要阅读this 才能理解为什么 RexEx 和 HTML 解析不能结合使用。
-
改用HTML Parser。
-
您无法使用正则表达式解析 HTML。大多数语言都有 HTML 解析器,在线查找或 HTML 解析器。如果你想自己做,你需要做更多的工作。