逍遥游

一直在想,怎样路好走一点,一直想,一直在崎岖中徘徊。
posts - 60, comments - 20, trackbacks - 0, articles - 28
   :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理

.NET中获取客户端HTML代码

Posted on 2007-06-06 09:56 逍遥游 阅读(69) 评论(0)  编辑 收藏 所属分类: .Net技术
///   <summary> 
  ///   传入URL返回网页的html代码 
  ///   </summary> 
  ///   <param   name="Url">URL</param> 
  ///   <returns></returns> 
  public   static     string   getUrltoHtml(string   Url) 
  { 
  errorMsg   =   ""; 
  try 
  { 
  System.Net.WebRequest   wReq   =   System.Net.WebRequest.Create(Url); 
  //   Get   the   response   instance. 
  System.Net.WebResponse   wResp   =wReq.GetResponse(); 
  //   Read   an   HTTP-specific   property  
  //   Get   the   response   stream. 
  System.IO.Stream   respStream     =   wResp.GetResponseStream(); 
  //   Dim   reader   As   StreamReader   =   New   StreamReader(respStream) 
  System.IO.StreamReader   reader   =   new   System.IO.StreamReader(respStream,   System.Text.Encoding.GetEncoding("gb2312")); 
  return     reader.ReadToEnd(); 
  
  } 
  catch(System.Exception   ex) 
  { 
Chinaz.com

  errorMsg   =   ex.Message   ; 
  } 
  return   ""; 
  } 
  
  你可以用这个函数获取网页的客户端的html代码,然后保存到.html文件里就可以了。 

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      


相关链接: