想把一个HTML文件另存为TXT格式的。
请问如何操作。
注意,不是直接修改文件后缀,是要“另存为”txt格式。
比如百度,另存为显示
百度一下,你就知道登录
新 闻网 页贴 吧知 道MP3图 片视 频
帮助
高级
空间 hao123 | 更多>>
把百度设为主页企业推广 | 搜索风云榜 | 关于百度 | About Baidu©2008 Baidu 使用百度前必读 京ICP证030173号
请问如何操作。
注意,不是直接修改文件后缀,是要“另存为”txt格式。
比如百度,另存为显示
百度一下,你就知道登录
新 闻网 页贴 吧知 道MP3图 片视 频
帮助
高级
空间 hao123 | 更多>>
把百度设为主页企业推广 | 搜索风云榜 | 关于百度 | About Baidu©2008 Baidu 使用百度前必读 京ICP证030173号
解决方案 »
- 请问用socket 如何发送字符串数组啊?? 谢谢了!!!
- 关于c#中Applition方面的问题,急等!
- windows xp/2003 下 vs 2005 中 datetimepicker 问题
- 100分求助:E都市的三维地图很漂亮,是用什么工具做的啊?
- 在winform中两页面如何传参 如何转换
- 帮忙看下解释下这段程序(asp.net ajax)
- c#中能否调用VC++6.0写的dll
- 请我如何在ComboBox文字的前面加上图片,急,马上结贴?
- 求助:并非所有的代码路径都返回值
- string 转换为 int ?
- dgv的自定义列的显示顺序问题
- DataGridView中指定了列的显示顺序,为什么一运行就乱了呢????
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号
*/
再麻烦各位一下了。
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();
using System.IO;
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是什么东东呢?
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();
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;啊
搞定了,谢谢各位。