获取远程网页的内容之二(downmoon原创)

本机直接上网时,请参看
获取远程网页的内容之一(downmoon原创)

本文仅针AD下代理上网的情况:
代码如下:
1、定义变量:

 定义变量


方法:
获取指定远程网页内容

 /// <summary>
        
/// 获取指定远程网页内容
        
/// </summary>
        
/// <param name="strUrl">所要查找的远程网页地址</param>
        
/// <returns></returns>

        //[WebMethod(Description = "获取指定远程网页内容。")]
        public string getPageContent(string strUrl)
        
{
            
string strResult        =    "";
            
this.CurrentUrl    =     strUrl;
            
if(this.CurrentUrl.ToLower().StartsWith("http://")==false)
                
this.CurrentUrl = "http://"+this.CurrentUrl;
            
try
            
{
                contentBytes    
= GetHtmlByte(CurrentUrl);
            
            }

            
catch(Exception err)
            
{
                strResult 
= "请求错误:" + err.Message;
            }

            
if(contentBytes==null)
            
{
                
throw new Exception("没有获得返回值");
            }

            strResult        
=    getStringFromByteArray(contentBytes,Encoding.UTF8);
            
return strResult;
        }




获取指定远程网页元素字节数组::

 获取指定远程网页元素字节数组



转换指定字节数组为字符串::

     转换指定字节数组为字符串




借用这个,写了个抽取中国天气网预报的服务!很爽!

在webForm中WebRequest\WebClient\WebBrowser获取远程页面源码的三种方式(downmoon)
posted @ 2007-12-29 11:50  邀月  阅读(3441)  评论(0编辑  收藏  举报