And*_*air 3 html c# html-agility-pack
早上好!我正在使用c#(框架3.5sp1),并希望通过正则表达式解析以下html片段:
<h1>My caption</h1>
<p>Here will be some text</p>
<hr class="cs" />
<h2 id="x">CaptionX</h2>
<p>Some text</p>
<hr class="cs" />
<h2 id="x">CaptionX</h2>
<p>Some text</p>
<hr class="cs" />
<h2 id="x">CaptionX</h2>
<p>Some text</p>
Run Code Online (Sandbox Code Playgroud)
我需要以下输出:
我有什么atm:
<hr.*?/>
<h2.*?>(.*?)</h2>
([\W\S]*?)
<hr.*?/>
Run Code Online (Sandbox Code Playgroud)
由于尾随,这将给我每个奇怪的子标题+内容(例如,1,3,...)<hr/>.为了解析h1-caption我有另一个模式(<h1.*?>(.*?)</h1>),它只给我标题而不是内容 - 我对那个atm很好.
有没有人为我提供提示/解决方案或任何替代逻辑(例如通过阅读器解析html并以这种方式分配?)?
编辑:
正如一些HTMLAgilityPack带来的,我很好奇这个漂亮的工具.我完成了<h1>-tag的内容.
但是...我的问题是解析其余部分.这是由于:内容的标签可能会有所不同 - 从<p>to <div>和<ul>... atm这似乎或多或少地遍历整个文档并解析标签标签......?任何提示?
| 归档时间: |
|
| 查看次数: |
2181 次 |
| 最近记录: |