求提取html中纯文本的正则表达式 这个非常难做啊不是一般的难如果内容中包含了<script>这样的东西,你去掉了,内容就不全了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不用考虑那么复杂的情况,就做到提取结果跟浏览器里按ctrl+c复制出的差不多就行了 现在国内很多网站页面都是用 javascript 脚本动态生成的,没有 javascript 引擎支持,很多页面是看不到内容的,更别想 ctrl+c 了。 public static String GetNormalText(String tempValue) { String t = tempValue; String pattern = @"(<style.*?>[\s|\S|.]*?</style>)|(<style.*?>)"; t = ReplaceContent(pattern, t); pattern = @"(<script.*?>[\s|\S|.]*?</script>)|(<script[\s|\S|.]*?>)"; t = ReplaceContent(pattern, t); //替换文件里面加入的脚本 pattern = @"((onclick)|(onload))=.+?[""|']"; t = ReplaceContent(pattern, t); //去掉注释 pattern = @"<!--[\s|.|\S].*?-->"; t = ReplaceContent(pattern, t); return t; } public static String ReplaceContent(String pattern, String tempValue) { Regex reg = new Regex(pattern, RegexOptions.Multiline | RegexOptions.IgnoreCase); return reg.Replace(tempValue, ""); }这是我帮别人做采集的时候写的,去掉js,等。 关于地图缩放 点击添加样式,然后取消其他样式(在线等阿),着急...... firefox下文本框调不出js日期组件 {急~求助大侠}请问怎么用JSP实现一个可以记录事件的日历模块??? 急急急 如何点击按钮跳转页面,在ASP里怎么做,zai 怎么对document做xpath查询? 点击一个CHM文件连接后,能不能直接打开,没有或跳过选择“打开”、“保存”什么的界面。 关于使用Wscript的问题 为什么这个错误只在IE5上有错,怎样解决这个问题呢?? 如何作链接javascript程序 请教一个关于url的正则表达式 求一个静态的联动下拉框
就做到提取结果跟浏览器里按ctrl+c复制出的差不多就行了
String t = tempValue;
String pattern = @"(<style.*?>[\s|\S|.]*?</style>)|(<style.*?>)";
t = ReplaceContent(pattern, t); pattern = @"(<script.*?>[\s|\S|.]*?</script>)|(<script[\s|\S|.]*?>)";
t = ReplaceContent(pattern, t); //替换文件里面加入的脚本
pattern = @"((onclick)|(onload))=.+?[""|']";
t = ReplaceContent(pattern, t); //去掉注释
pattern = @"<!--[\s|.|\S].*?-->";
t = ReplaceContent(pattern, t);
return t;
} public static String ReplaceContent(String pattern, String tempValue) {
Regex reg = new Regex(pattern, RegexOptions.Multiline | RegexOptions.IgnoreCase);
return reg.Replace(tempValue, "");
}这是我帮别人做采集的时候写的,去掉js,等。