none
不錯的介面喔! ^_^ RRS feed

  • General discussion

  • 可以修改HTML耶

    測試發佈!

    1 using System;  
    2 using System.IO;  
    3 using System.Net;  
    4 using HtmlAgilityPack;  
    5  
    6 namespace ConsoleFx.Samples.Aspx2Html  
    7 {  
    8     //aspx2html <url> [<output directory>] [-recursive] [-removescript]  
    9  
    10     [CommandLine]  
    11     [ParameterUsage(ProgramMode.Normal, MinOccurences = 1, MaxOccurences = 2)]  
    12     [ParameterUsage(ProgramMode.Help, MinOccurences = 0, MaxOccurences = 0)]  
    13     public sealed class Program : ConsoleProgram  
    14     {  
    15         public override int ExecuteNormal(string[] parameters)  
    16         {  
    17             string url = parameters[0];  
    18             string html;  
    19             using (WebClient webClient = new WebClient())  
    20                 html = webClient.DownloadString(url);  
    21  
    22             HtmlDocument doc = new HtmlDocument();  
    23             doc.LoadHtml(html);  
    24             HtmlNode root = doc.DocumentNode;  
    25  
    26             HtmlNode removalNode = root.SelectSingleNode(@"//html/body/input[@name='__VIEWSTATE' and @id='__VIEWSTATE' and @type='hidden']");  
    27             if (removalNode != null)  
    28                 removalNode.RemoveAll();  
    29  
    30             removalNode = root.SelectSingleNode(@"//html/body/input[@name='__EVENTVALIDATION' and @id='__EVENTVALIDATION' and @type='hidden']");  
    31             if (removalNode != null)  
    32                 removalNode.RemoveAll();  
    33  
    34             Uri uri = new Uri(url);  
    35             string filename = Path.ChangeExtension(uri.Segments[uri.Segments.Length - 1], "html");  
    36             string filepath = Path.Combine(@"D:\Temp", filename);  
    37             using (StreamWriter sw = new StreamWriter(filepath, false))  
    38                 sw.Write(root.WriteTo());  
    39               
    40             return 0;  
    41         }  
    42  
    43         public override int SetMode(string[] parameters)  
    44         {  
    45             return ProgramMode.Normal;  
    46         }  
    47  
    48         public static int Main(string[] args)  
    49         {  
    50             return CommandLine.Run<Program>(args);  
    51         }  
    52     }  
    53 }  
    54  

     

    感覺不錯!

    Sunday, January 25, 2009 6:01 AM

All replies

  • cool, 回覆文章的時候上方的區塊可以瀏覽回復中的原文內容~~ cool ~
    態度決定一切 ! - blog : http://bauann-makeit.blogspot.com/
    Monday, January 26, 2009 6:56 AM