正在阅读:从网上抓取指定URL源码的方案从网上抓取指定URL源码的方案

2004-03-25 14:32 出处:CSDN 作者:rexsp 责任编辑:linjixiong

    if(this.proxyPort==null)
     this.ProxyPort="80";

    WebProxy myProxy=new WebProxy();
    myProxy = (WebProxy)request.Proxy;
    myProxy.Address = new Uri(this.ProxyAddress+":"+this.ProxyPort);
    myProxy.Credentials = new NetworkCredential(this.proxyAccount, this.proxyPassword, this.ProxyDomain);
    request.Proxy = myProxy;
   }
   try
  
   {
    //请求服务
    WebResponse response = request.GetResponse();
    //返回信息
    Stream resStream = response.GetResponseStream();
    StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default);
    string tempCode= sr.ReadToEnd();
    resStream.Close();
    sr.Close();

    //如果输出文件路径为空,便将得到的内容赋给OutString属性
    if(this.outFilePath==null)
    {
     this.outString=tempCode;
    }
    else
    {

     FileInfo fi = new FileInfo(this.outFilePath);
     //如果存在文件则先干掉
     if(fi.Exists)
      fi.Delete();
     StreamWriter sw = new StreamWriter(this.outFilePath,true,Encoding.Default);
     sw.Write(tempCode);
     sw.Flush();
     sw.Close();
    }
   }
   catch
   {
    this.noteMessage="出错了,请检查网络是否连通;";
     }

      }
   #endregion

   }
  }


察看评论详细内容 我要发表评论
作者笔名 简短内容 发表时间
:
键盘也能翻页,试试“← →”键

关注我们

最新资讯离线随时看 聊天吐槽赢奖品