c#正则匹配指定地址指定div内容

 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();
        }

    }




//获取页面内容

/// <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;

    }


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值