我自己写的A.aspx网页,现server.transfer("B.aspx").当中还进行了session的传递。
等生成B.aspx后,我需要将B.aspx保存下来,并提取它的网页源代码。如何实现啊?
谢谢了。

解决方案 »

  1.   

    帮你顶一个====CSDN 小助手 V2.5 2005年11月05日发布====
    CSDN小助手是一款脱离浏览器也可以访问Csdn论坛的软件
    界面:http://blog.csdn.net/Qqwwee_Com/archive/2005/11/05/523395.aspx
    下载:http://szlawbook.com/csdnv2
      

  2.   

    http://blog.csdn.net/shoutor/archive/2006/03/13/623422.aspx
      

  3.   

    上面的方法是通过WebClient来抓取数据你只需要下面的代码:string xmlPath = @"http地址"; 
    DataSet ds = new DataSet();
    WebClient wc = new WebClient();
    byte[] bt = wc.DownloadData(xmlPath); XmlDocument xd = new XmlDocument();string source = Byte2String(bt);需要引入System.Net
      

  4.   

    进行了session传送值的,楼上的方法好像不行吧?
      

  5.   

    是啊。这就是我的问题。。shoutor() 这位兄弟说的,我也知道。只是实现不了啊。
      

  6.   

    需要用到HttpWebRequest的CookieContainer属性,代码参考:
    http://community.csdn.net/Expert/TopicView.asp?id=4066881
    把里面注释掉的几段程序恢复就可以了
      

  7.   

    aspx代码你得不到,只能得到解析过的html
      

  8.   

    孟子E章大哥,终于看到你回我的帖了。对的,我只要求得到我想要的html代码就好了。不想要源代码啊,还请孟子大哥给点好的建议。另外现在发的email里面的内容就是一个网页的形式,应该就是我想要的效果,这效果是直接输出html文件得到的吧。
      

  9.   

    fancyf(凡瑞)大哥,刚刚仔细研究了下你的代码。
    现有几个问题,还请你帮忙解释下。
    因为我要获取的B.ASPX页面,是从A.aspx传过去的,而传过去的是session,而不是通过b.aspx?parameter=???这方式传过去的。
    用string   url   =   "http://bbs.wowchina.com/bbs/bbs_list.aspx?forum_id=4&page_no="   +   mPage;
    Uri   target   =   new   Uri(url);
    HttpWebRequest   request   =   (HttpWebRequest)HttpWebRequest.Create(target);
    HttpWebResponse   response   =   (HttpWebResponse)request.GetResponse()
    这样获取的页面没有session的吧。那这么得到的结果肯定不是我想要的页面。因为里面处理的数据都不对。
    还请fancyf(凡瑞)大哥再指点下小弟。万分感谢。
      

  10.   

    我那段代码里面有可以保存Cookie的代码,你可能没注意
    不过我看你用Server.Transfer来转换页面的,客户段并没有任何变化
    你用WebClient直接下载a.aspx的url所得到的内容就是Server.Transfer之后的b.aspx的内容
      

  11.   

    给你一个方法,返回的是网页的html代码!
    public string GetUrl_Text(string urls,string SeverName)
    {
    string   localDir   =   @"E:\Website"; if   (!Directory.Exists(localDir))
    {
    Directory.CreateDirectory(localDir);
    Console.WriteLine("Directory   {0}   Created!!!",   localDir);
    } //Uncomment   the   next   2   lines   to   save   cookies   from   the   site
    CookieContainer   cookieContainer   =   new   CookieContainer();
    Uri   bbsRoot   =   new   Uri(SeverName); string   url   =   urls;
    Uri   target   =   new   Uri(url);
    try
    {
    HttpWebRequest   request   =   (HttpWebRequest)HttpWebRequest.Create(target);
    request.AllowAutoRedirect   =   false;
    request.Accept   =   "*/*";
    request.Headers.Add("Accept-Language",   "zh-cn");
    request.Headers.Add("Accept-Encoding",   "gzip,   deflate");
    request.UserAgent   =   "Mozilla/4.0   (compatible;   MSIE   6.0;   Windows   NT   5.2;   .NET   CLR   1.1.4322)"; //Uncomment   the   next   4   lines   to   use   a   proxy
    WebProxy   myProxy   =   new   WebProxy();
    Uri   newUri=new   Uri(SeverName);
    myProxy.Address   =   newUri;
    request.Proxy   =   myProxy; //Uncomment   the   next   4   lines   to   save   cookies   from   the   site
    if   (cookieContainer.Count   >   0)
    {
     request.CookieContainer   =   cookieContainer;
    } string   content   =   "";
    using(HttpWebResponse   response   =   (HttpWebResponse)request.GetResponse())
    {
    //Uncomment   the   next   4   lines   to   save   cookies   from   the   site
    if   (response.Headers["SetCookies"]   !=   null   &&   response.Headers["SetCookies"]   !=   string.Empty)
    {
     cookieContainer.SetCookies(bbsRoot,response.Headers["SetCookies"]);
    } using(StreamReader   sr   =   new   StreamReader(response.GetResponseStream(),   System.Text.Encoding.Default,   true))
    {
    content   =   sr.ReadToEnd();
    } } return content;
    }
    catch   (WebException   e)
    {
    return e.Message;
    }
    catch   (IOException   e)
    {
    return e.Message;
    }
    }
      

  12.   

    你的有Session传递!
    这个就只有传递Cookies!
    我改了一些!下面是最后的代码!
    public string GetUrl_Text(string urls,string SeverName)
    {
    //Uncomment   the   next   2   lines   to   save   cookies   from   the   site
    CookieContainer   cookieContainer   =   new   CookieContainer();
    Uri   bbsRoot   =   new   Uri(SeverName); Cookie Cookies1=new Cookie("Chars","Bit5");//创建Cookie cookieContainer.Add(bbsRoot,Cookies1);//添加Cookie string   url   =   urls;
    Uri   target   =   new   Uri(url);
    try
    {
    HttpWebRequest   request   =   (HttpWebRequest)HttpWebRequest.Create(target);
    request.AllowAutoRedirect   =   false;
    request.Accept   =   "*/*";
    request.Headers.Add("Accept-Language",   "zh-cn");
    request.Headers.Add("Accept-Encoding",   "gzip,   deflate");
    request.UserAgent   =   "Mozilla/4.0   (compatible;   MSIE   6.0;   Windows   NT   5.2;   .NET   CLR   1.1.4322)"; //Uncomment   the   next   4   lines   to   use   a   proxy
    WebProxy   myProxy   =   new   WebProxy();
    Uri   newUri=new   Uri(SeverName);
    myProxy.Address   =   newUri;
    request.Proxy   =   myProxy; //Uncomment   the   next   4   lines   to   save   cookies   from   the   site
    if   (cookieContainer.Count   >   0)
    {
     request.CookieContainer   =   cookieContainer;
    } string   content   =   "";
    using(HttpWebResponse   response   =   (HttpWebResponse)request.GetResponse())
    {
    //Uncomment   the   next   4   lines   to   save   cookies   from   the   site
    if   (response.Headers["SetCookies"]   !=   null   &&   response.Headers["SetCookies"]   !=   string.Empty)
    {
     cookieContainer.SetCookies(bbsRoot,response.Headers["SetCookies"]);
    } using(StreamReader   sr   =   new   StreamReader(response.GetResponseStream(),   System.Text.Encoding.Default,   true))
    {
    content   =   sr.ReadToEnd();
    } } return content;
    //StreamWriter   sw   =   new   StreamWriter(localDir   +   "\\Page.htm",   false,   System.Text.Encoding.Default);
    //sw.Write(content);
    //sw.Close();
    //Console.WriteLine("oh   ye~~   :   {0}   download!!!",   localDir   +   "\\Page.html");
    }
    catch   (WebException   e)
    {
    return e.Message;
    }
    catch   (IOException   e)
    {
    return e.Message;
    }
    } }================================
    我测试以后是正确的!Response.Write(GetUrl_Text("http://www.wise111.com/Union_Services.asp","http://www.wise111.com"));
      

  13.   

    刚测试了下,fancyf(凡瑞) 大哥,
    当a.aspx===>transfer到b.aspx文件
    我在b.aspx执行
    public string GetUrl_Text(string urls,string SeverName)
    {
    //Uncomment   the   next   2   lines   to   save   cookies   from   the   site
    CookieContainer   cookieContainer   =   new   CookieContainer();
    Uri   bbsRoot   =   new   Uri(SeverName); Cookie Cookies1=new Cookie("Chars","Bit5");//创建Cookie cookieContainer.Add(bbsRoot,Cookies1);//添加Cookie string   url   =   urls;
    Uri   target   =   new   Uri(url);
    try
    {
    HttpWebRequest   request   =   (HttpWebRequest)HttpWebRequest.Create(target);
    request.AllowAutoRedirect   =   false;
    request.Accept   =   "*/*";
    request.Headers.Add("Accept-Language",   "zh-cn");
    request.Headers.Add("Accept-Encoding",   "gzip,   deflate");
    request.UserAgent   =   "Mozilla/4.0   (compatible;   MSIE   6.0;   Windows   NT   5.2;   .NET   CLR   1.1.4322)"; //Uncomment   the   next   4   lines   to   use   a   proxy
    WebProxy   myProxy   =   new   WebProxy();
    Uri   newUri=new   Uri(SeverName);
    myProxy.Address   =   newUri;
    request.Proxy   =   myProxy; //Uncomment   the   next   4   lines   to   save   cookies   from   the   site
    if   (cookieContainer.Count   >   0)
    {
    request.CookieContainer   =   cookieContainer;
    } string   content   =   "";
    using(HttpWebResponse   response   =   (HttpWebResponse)request.GetResponse())
    {
    //Uncomment   the   next   4   lines   to   save   cookies   from   the   site
    if   (response.Headers["SetCookies"]   !=   null   &&   response.Headers["SetCookies"]   !=   string.Empty)
    {
    cookieContainer.SetCookies(bbsRoot,response.Headers["SetCookies"]);
    } using(StreamReader   sr   =   new   StreamReader(response.GetResponseStream(),   System.Text.Encoding.Default,   true))
    {
    content   =   sr.ReadToEnd();
    } } return content;
    //StreamWriter   sw   =   new   StreamWriter(localDir   +   "\\Page.htm",   false,   System.Text.Encoding.Default);
    //sw.Write(content);
    //sw.Close();
    //Console.WriteLine("oh   ye~~   :   {0}   download!!!",   localDir   +   "\\Page.html");
    }
    catch   (WebException   e)
    {
    return e.Message;
    }
    catch   (IOException   e)
    {
    return e.Message;
    }
    }函数
    如果是请求a.aspx的话,则得到是a.aspx的文件,取不到b.aspx文件。
    设为b.aspx也是不行。另外还有一个问题就是那些gif图片怎么修改成绝对连接啊?
    请高手帮帮我。谢谢
      

  14.   

    dingsongtao(一翁傾塵『舍得』) 
    你的意思是否是,我不要用session来传递,用cookiee来传递?
    我试了下你的方法,结果也是一样的。
    a.aspx===>b.aspx
    传输了session("userid")
    所以
    咳,还请高手解决。
      

  15.   

    看着有点糊涂,看看
    http://lovecherry.cnblogs.com/archive/2005/06/18/176791.html
    有用吗
      

  16.   

    yuwen16(rr) 
    ===========
    就是不要用Session,改成Cookie来传递!我测试都是行的!
    我上面发的那个函数!
    Cookie Cookies1=new Cookie("Chars","Bit5");//创建Cookie
    cookieContainer.Add(bbsRoot,Cookies1);//添加Cookie意思就是建立一个Cookie名字为:Chars,值为:Bit5的Cookie!
    并添加到cookieContainer里面去!我添加的Cookie是对应的:Response.Write(GetUrl_Text("http://www.wise111.com/Union_Services.asp","http://www.wise111.com"));这个网站的抓取!
    这个网站是用Cookie值来判定显示繁体还是简体的!我测试都是可以的!你要添加什么样的Cookie就自己做一下修改!这个方法还可以改进一下的!==========
    要想严谨一点的话,最好在你提取的页面里的图片路径就用绝对的地址!
      

  17.   

    个人考虑觉得cookie不是很安全吧。这里还要加密的。
    因为项目一早就用了session,也不想改了。
    谢谢各位大哥们。
    结贴。