首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

正则页面内容婚配

2013-07-01 
正则页面内容匹配比如:http://news.sina.com.cn/c/2013-06-26/115227502792.shtml匹配它的标题和里面的内

正则页面内容匹配
比如:http://news.sina.com.cn/c/2013-06-26/115227502792.shtml

匹配它的标题和里面的内容。

正则
[解决办法]
标题 (?i)<h1[^>]*?id=(['""]?)artibodyTitle\1[^>]*?>(?<Title>[^<>]*?)</h1>
去分组 Groups["Title"].value

内容 (?i)<div[^>]*?id=(['""]?)artibody\1[^>]*?>[\s\S]*?<p>\s*?(?<Content>[^<>]*?)\s*?</p>[\s\S]*?</div>

去分组 Groups["Content"].value
[解决办法]
1、
string patternTitle=@"(?is)<h1[^>]*?id=""artibodyTitle""[^>]*?>(?<Title>.*?)</h1>";
取Groups.Groups["Title"].Value



2、
string patternContent=@"(?is)<div[^>]*?id=""artibody""[^>]*?>[\s\S]*?<p>(?<Content>.*?)</p>[\s\S]*?</div>";
取Groups.Groups["Content"].Value

热点排行