using System; using System.Windows.Forms; using System.IO; using System.Text; using System.Text.RegularExpressions; namespace hiddenBrowser { static class Program { /// /// アプリケーションのメイン エントリ ポイントです。 /// [STAThread] static void Main(String[] arg) { if (arg.Length != 2) { Console.WriteLine("usage:\n hiddenBrowser URL fileName"); Application.Exit(); } else { Console.WriteLine("hiddenBrowser {0} {1}",arg[0],arg[1]); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); hiddenBrowserForm f = new hiddenBrowserForm(arg[0]); Application.Run(f); outputContent(f.firstString, arg[1]); } } static public void outputContent(String firstString, String FileName) { try { Regex regCrlf = new Regex(@"(\r\n|\r|\n)"); Regex regTagStyle = new Regex(@"<[sS][tT][yY][lL][eE].*?>.*?", RegexOptions.Singleline); Regex regTagScript = new Regex(@"<[sS][cC][rR][iI][pP][tT].*?>.*?", RegexOptions.Singleline); Regex regTagNoScript = new Regex(@"<[nN][oO][sS][cC][rR][iI][pP][tT].*?>.*?", RegexOptions.Singleline); Regex regTagBr = new Regex(@"<[bB][rR].*?/*>"); Regex regTagP = new Regex(@""); Regex regTags = new Regex(@"<.+?>", RegexOptions.Singleline); Regex regBlanks = new Regex(@"( | |\t| ){1,}\n", RegexOptions.Singleline); Regex regCrlf2 = new Regex(@"\n{2,}", RegexOptions.Singleline); Regex regCrlf3 = new Regex(@"^\n{1,}", RegexOptions.Singleline); String ans = firstString; ans = regCrlf.Replace(ans, "\n"); ans = regTagStyle.Replace(ans, ""); ans = regTagScript.Replace(ans, ""); ans = regTagNoScript.Replace(ans, ""); ans = regTagBr.Replace(ans, "\n"); ans = regTagP.Replace(ans, "\n"); ans = regTags.Replace(ans, ""); ans = regBlanks.Replace(ans, "\n"); ans = regCrlf2.Replace(ans, "\n"); ans = regCrlf3.Replace(ans, ""); FileStream fs = new FileStream(FileName, FileMode.Create); Encoding ec = Encoding.UTF8; byte[] bf = ec.GetBytes(ans.ToCharArray()); fs.Write(bf, 0, bf.Length); fs.Flush(); fs.Close(); } catch (Exception ee) { Console.WriteLine(ee.Message); } } } }