string http = "http://www.baidu.com";
            System.Net.WebRequest request = System.Net.WebRequest.Create(http);
            System.IO.StreamReader sr = new System.IO.StreamReader(request.GetResponse().GetResponseStream(), System.Text.Encoding.GetEncoding("gb2312"));我想抓取一个网页,同一个网址,在浏览器里输是有值的,用上面这段代码却无返回值,但用上面这代码搜百度是有值的
这是为什么?是不是那网站用了什么技术屏蔽抓取,怎么解决?

解决方案 »

  1.   

    这方面我刚学习 昨天看到一篇 不知道是否满足你的需求
    http://www.cnblogs.com/lixiaofei/archive/2012/02/16/2353795.html
      

  2.   

    http://www.cnblogs.com/haiconc/archive/2012/02/13/2349914.html
      

  3.   

    试过了,也不行,连百度有值,连我的网址就为空了把我的网址贴上来,你们试试
    http://ribao.xoyo.com/jx3/92/:info=jx3_query_price%23server_k%3D0%23server_name%3D%E6%A2%A6%E6%B1%9F%E5%8D%97%2F%E5%A6%82%E6%A2%A6%E4%BB%A4%2F%E6%9E%AB%E6%B3%BE%E5%8F%A4%E9%95%87%23article_name%3D%E7%A7%98%E6%96%B9%EF%BC%9A%E7%82%B8%E6%98%A5%E5%8D%B7%23pageno%3D1%23order_column%3Dbin_high_price%23order_type%3DASC%23nu%3D这条网址在浏览器中会返回一个josn字符串,如下var data = {"list":[{"aid":"77692","article_name":"\u79d8\u65b9\uff1a\u70b8\u6625\u5377","article_nums":"2","nSortID":"8","tSubSort":"2","bin_high_price":"12500000","bin_low_price":"12500000","bin_average_price":"12500000","a_high_price":"12000000","a_low_price":"12000000","a_average_price":"12000000","server_k":"0","server_name":"\u68a6\u6c5f\u5357\/\u5982\u68a6\u4ee4\/\u67ab\u6cfe\u53e4\u9547","operatetime":"2012-02-17 03:45:17"}],"config":["\u7535\u4fe1","\u7f51\u901a"],"counts":"1"}
    但在程序里就返回一个空串了,如下var data = {\"list\":null,\"config\":[\"\\u7535\\u4fe1\",\"\\u7f51\\u901a\"],\"counts\":\"0\"}
    怎么办
      

  4.   

    WebRequest自动将"梦江南/如梦令/枫泾古镇"中的"/"进行了编码,请求地址变了
    如果"/"是传的值,理应进行编码,要不与目录容易搞混
      

  5.   

    "/"是传的值,可我不是已经编码了,完整代码如下
                string sItemName = "秘方:炸春卷";
                string http = "http://ribao.xoyo.com/jx3/190/:info=jx3_query_price";
                string query = "#server_k=0#server_name=梦江南/如梦令/枫泾古镇#article_name=" + sItemName + "#pageno=1#order_column=bin_high_price#order_type=ASC#nu=";            http = http + HttpUtility.UrlEncode (query);//Microsoft.JScript.GlobalObject.encodeURIComponent(query);
                System.Net.WebRequest request = System.Net.WebRequest.Create(http);
                System.IO.StreamReader sr = new System.IO.StreamReader(request.GetResponse().GetResponseStream(), System.Text.Encoding.GetEncoding("gb2312"));
                if (sr != null)
                {
                    string html = sr.ReadToEnd();
                }
      

  6.   

    用HttpUtility.UrlEncode (query);转的码,梦江南/如梦令/枫泾古镇里的"/"已经被转成%2f
      

  7.   

    编码在不同的站有所不同吧。。试试其他的Default  utf8什么的看看
      

  8.   

    好像是编码问题,如果我去掉“#server_name=梦江南/如梦令/枫泾古镇”是有返回的,可如果是编码问题,为啥我直接把HttpUtility.UrlEncode (query)转码后的链接输在浏览器里,也有返回值除了HttpUtility.UrlEncode还能怎么转码?!