查找文件的HTML字符串 [英] Finding HTML strings in document

查看:109
本文介绍了查找文件的HTML字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得的所有HTML < P> ...< / P> 在文档
使用正则表达式找到使用所有这样的字符串:

I want to get all HTML <p>...</p> in a document.
Using Regex to find all such strings using:

Regex regex = new Regex(@"\<p\>([^\>]*)\</p\>", RegexOptions.IgnoreCase);

但我不能得到任何结果。有什么毛病我经常EX pression?

But I am not able to get any result. Is there anything wrong with my regular expression.?

现在,我只是想获得的一切,在与&LT; P&GT; ...&LT; / P&GT; 标签,并想用正则表达式这是源不是HTML文档

For now, I just want to get everything that comes in between <p>...</p> tags and want to use Regex for this as the source is not an HTML document.

推荐答案

相反,使用 HTML敏捷性包

例如:

var doc = new HtmlDocument();
doc.Load(...);

var pTags = doc.DocumentNode.Descendants("p");

修改:您可以做到这一点,即使该文件实际上不是HTML

EDIT: You can do this even if the document isn't actually HTML.

这篇关于查找文件的HTML字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆