想把一个HTML文件另存为TXT格式的。
请问如何操作。
注意,不是直接修改文件后缀,是要“另存为”txt格式。
比如百度,另存为显示
百度一下,你就知道登录
      新 闻网 页贴 吧知 道MP3图 片视 频
        帮助
      高级
空间  hao123 | 更多>>
把百度设为主页企业推广 | 搜索风云榜 | 关于百度 | About Baidu©2008 Baidu 使用百度前必读 京ICP证030173号 

解决方案 »

  1.   

    webclient 读到内存里。然后正则过滤标签,然后输出到txt就ok了。
      

  2.   

    大侠webclient 是什么东东呢?另外,是用WINFORM的,能举个简单的例子么?
      

  3.   

    黑简单的问题,c#如何操作HTML? 黑简单的问题是什么意思!@#$%^&*(.....
      

  4.   


                WebClient wc = new WebClient();
                string content = wc.DownloadString("http://www.baidu.com");
                Console.WriteLine(content);
                content = Regex.Replace(content, @"<style>[\s\S]*</style>", string.Empty);
                content = Regex.Replace(content, @"<script[\s\S]*>[\s\S]*</script>", string.Empty);
                content = Regex.Replace(content, @"<(?:.|\s)*?>", string.Empty);
                content = Regex.Replace(content, @"\&[^\;]*\;", " ");
                StreamWriter sw = File.CreateText("D:\\data.txt");
                sw.Write(content);
                sw.Close();
    /*
    data.txt中的内容:
    百度一下,你就知道      
    登录新 闻网 页贴 吧知 道MP3图 片视 频
      帮助高级
    空间  hao123 | 更多>>把百度设为主页企业推广 | 搜索风云榜 | 关于百度 | About Baidu 2008 Baidu 使用百度前必读 京ICP证030173号 
    */
      

  5.   

    冒泡简单的话用WebBrowser的ShowSaveAsDialog 
      

  6.   

    谢谢五楼的兄弟,其实html文件是在本地的机子上单个文件。不用考虑网络的问题哈。
    再麻烦各位一下了。
      

  7.   

    正则表达过滤,得到正文将<...>替换成null即String.Emptycontent = Regex.Replace(content, @"<(?:.|\s)*?>", string.Empty);
      

  8.   

            string content = File.ReadAllText(Server.MapPath(".")+"\\your.htm").ToString();
            content = Regex.Replace(content, @"<style>[\s\S]*</style>", string.Empty);
            content = Regex.Replace(content, @"<script[\s\S]*>[\s\S]*</script>", string.Empty);
            content = Regex.Replace(content, @"<(?:.|\s)*?>", string.Empty);
            content = Regex.Replace(content, @"\&[^\;]*\;", " ");        System.IO.StreamWriter sw = File.CreateText(Server.MapPath(".")+"\\data.txt");
            sw.Write(content);
            sw.Close();
      

  9.   

    注意引用 
    using System.IO;
      

  10.   


                string filename = "";
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.InitialDirectory = System.Windows.Forms.Application.StartupPath;
                dlg.Filter = "html文件 (*.html)|*.html";
                dlg.FilterIndex = 0;
                dlg.RestoreDirectory = true;
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    filename = dlg.FileName;
                }
                StreamReader fileStream = new StreamReader(filename, Encoding.Default);
                string content = fileStream.ReadToEnd();
                content = Regex.Replace(@"<style>[\s\S]*</style>", string.Empty);
                content = Regex.Replace(@"<script[\s\S]*>[\s\S]*</script>", string.Empty);
                content = Regex.Replace(@"<(?:.|\s)*?>", string.Empty);
                content = Regex.Replace(@"\&[^\;]*\;", " ");            StreamWriter sw = File.CreateText("D:\\data.txt");
                sw.Write(content);
                sw.Close();提示“当前上下文中不存在名称“Regex””,Regex是什么东东呢?
      

  11.   

    都写到这份上了,自己就不能琢磨琢磨            string content = System.IO.File.ReadAllText("D:\\index.html", Encoding.GetEncoding("gb2312"));
                Console.WriteLine(content);
                content = Regex.Replace(content, @"<style>[\s\S]*</style>", string.Empty);
                content = Regex.Replace(content, @"<script[\s\S]*>[\s\S]*</script>", string.Empty);
                content = Regex.Replace(content, @"<(?:.|\s)*?>", string.Empty);
                content = Regex.Replace(content, @"\&[^\;]*\;", " ");
                StreamWriter sw = File.CreateText("D:\\data.txt");
                sw.Write(content);
                sw.Close();
      

  12.   


                string filename = "";
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.InitialDirectory = System.Windows.Forms.Application.StartupPath;
                dlg.Filter = "html文件 (*.html)|*.html";
                dlg.FilterIndex = 0;
                dlg.RestoreDirectory = true;
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    filename = dlg.FileName;
                }            StreamReader fileStream = new StreamReader(filename, Encoding.Default);
                string content = fileStream.ReadToEnd();
                content = Regex.Replace(content,@"<style>[\s\S]*</style>", string.Empty);
                content = Regex.Replace(content, @"<script[\s\S]*>[\s\S]*</script>", string.Empty);
                content = Regex.Replace(content, @"<(?:.|\s)*?>", "");
                content = Regex.Replace(content, @"\&[^\;]*\;", " ");            StreamWriter sw = File.CreateText("D:\\data.txt");
                sw.Write(content);
                sw.Close();原来要导入using System.Text.RegularExpressions;啊
    搞定了,谢谢各位。