zoukankan      html  css  js  c++  java
  • 获取远程网页的内容之二(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)
    邀月注:本文版权由邀月和博客园共同所有,转载请注明出处。
    助人等于自助!  3w@live.cn
  • 相关阅读:
    Docker实战--部署简单nodejs应用
    VMWare下ubuntu无法全屏的问题解决
    CentOS 7安装Docker
    修改maven本地仓库的默认地址
    spring cloud 集成 swagger2 构建Restful APIS 说明文档
    使用Redis的INCR、Hsetnx、Hincrby的命令生成序列号
    NetMQ(四): 推拉模式 Push-Pull
    NetMQ(三): 发布订阅模式 Publisher-Subscriber
    NetMQ(二): 请求响应模式 Request-Reply
    NetMQ(一):zeromq简介
  • 原文地址:https://www.cnblogs.com/downmoon/p/1019701.html
Copyright © 2011-2022 走看看