c#正则匹配指定地址指定div内容
2017-08-01 11:43
246 查看
public string html = "";
protected void Page_Load(object sender, EventArgs e)
{
html = GetHtml("http://1680210.com/html/PK10/pk10kai_luzhufxzh.html");
//Regex reg = new Regex(@"(?m)<title[^>]*>(?<title>(?:\w|\W)*?)</title[^>]*>", RegexOptions.Multiline | RegexOptions.IgnoreCase);
Regex reg = new Regex(@"(?m)<div class=""listbox""[^>]*>(?<div>(?:\w|\W)*?)</div[^>]*>", RegexOptions.Multiline | RegexOptions.IgnoreCase);
Match mc = reg.Match(html);
if (mc.Success)
{
html = mc.Groups["div"].Value.Trim();
}
}
//获取页面内容
protected void Page_Load(object sender, EventArgs e)
{
html = GetHtml("http://1680210.com/html/PK10/pk10kai_luzhufxzh.html");
//Regex reg = new Regex(@"(?m)<title[^>]*>(?<title>(?:\w|\W)*?)</title[^>]*>", RegexOptions.Multiline | RegexOptions.IgnoreCase);
Regex reg = new Regex(@"(?m)<div class=""listbox""[^>]*>(?<div>(?:\w|\W)*?)</div[^>]*>", RegexOptions.Multiline | RegexOptions.IgnoreCase);
Match mc = reg.Match(html);
if (mc.Success)
{
html = mc.Groups["div"].Value.Trim();
}
}
//获取页面内容
/// <summary> /// 获取页面类容 /// </summary> /// <param name="strUrl"></param> /// <returns></returns> public static string GetHtml(string strUrl) { string content; HttpWebRequest httpRequest = (HttpWebRequest)HttpWebRequest.Create(strUrl); httpRequest.Referer = strUrl; httpRequest.UserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 7\\_1\\_2 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/11D257 MicroMessenger/5.3.1like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4"; httpRequest.Accept = "text/html, application/xhtml+xml, */*"; httpRequest.ContentType = "application/x-www-form-urlencoded"; httpRequest.Method = "GET"; HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse(); using (Stream responsestream = httpResponse.GetResponseStream()) { using (StreamReader sr = new StreamReader(responsestream, System.Text.Encoding.UTF8)) { content = sr.ReadToEnd(); } } return content; }
相关文章推荐
- C# 正则表达式匹配多层嵌套的括号里面的内容 百度api逆地址解析
- 正则 匹配所有指定内容中的链接
- HTML to Image in C#指定网页地址,获取内容为图片
- C#正则表达式匹配HTML中的图片路径,图片地址
- C#正则表达式只替换指定第几次匹配…
- C#正则表达式匹配HTML中的图片路径,图片地址代码
- C#正则表达式匹配HTML中的图片路径,图片地址
- C# 正则表达式获取指定标签的内容
- .net c# 如何获指定地址的网页内容标签
- C#正则表达试来读取网页所有内容里的链接地址和链接内容
- 用 C# 的正则表达式匹配 HTML 中的图片地址 (转的)
- C#正则表达式匹配HTML中的图片路径,图片地址
- 正则表达式匹配指定字符之间的内容,不含首尾字符
- php正则匹配html中带class的div并选取其中内容的方法
- 正则-匹配超链接地址及内容
- C#正则表达式匹配HTML中的图片路径,图片地址
- c#在指定内容中通过正则查找字符
- 通过C#采集指定地址页面内容
- C#正则表达式获取组名,按照组名输出匹配内容
- 正则-匹配超链接地址及内容