给一个IP,要求获取IP对应的网页部分信息,例如:给你百度IP:202.181.111.148,通此IP能否只把百度页面<head>...</head>中的信息下载下来,<body>部分不要下载,节约流量(从网上找下,只能给URL下载网页的,而且是全部下载)

解决方案 »

  1.   

    string netUrl = "http://www.baidu.com";
    HttpWebRequest myWebRequest = (HttpWebRequest)WebRequest.Create(netUrl);
    WebResponse resp = myWebRequest.GetResponse();
    StreamReader oStreamRd = new StreamReader(resp.GetResponseStream(), Encoding.GetEncoding("GB2312"));
    string content = oStreamRd.ReadToEnd();
    Match regSelect = Regex.Match(content, @"<head>(?<content>.+?)</head>", RegexOptions.Singleline | RegexOptions.IgnoreCase);
    if (regSelect.Success)
    {
        content =  "" + regSelect.Groups["content"].Value + "";

    自己想要什么,就对content做正则处理,大概就是这个样子了。
      

  2.   

    想搞个扫描IP段的东西,通过IP获取网页部分内容,觉得整个页面下载后在分析会比较慢,所以想部分下载网页