网络神采关键词过滤NET插件
此处代码仅供参考,完整代码请下载附件阅读。
不说废话,直接贴代码:
插件接口实现:
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Bget.Plugin;namespace HX_Plug
{public class Plug : IBget //插件接口{//创建插件public void Create(string taskPath, string pluginPath, BgetInformation bgetInfo, Action action, bool firstCall){this.WriteLog("创建插件...");}//销毁插件public void Dispose(Bget.Plugin.Action action){this.WriteLog("销毁插件...");}//正在下载内容文件public void DownloadContentFile(string url, string path, bool skipIfFileExisted, string cookie, string referer){this.WriteLog("正在下载内容文件...");}//正在下载独立文件public string DownloadSingleFile(string url, string path, string fileNamePrefix, bool skipIfFileExisted, string cookie, string referer){this.WriteLog("正在下载独立文件...");return fileNamePrefix + Path.GetFileName(path);}//提取结果public string ExtractResult(string extractionRule, string dataColumn, string htmlText, string url){this.WriteLog("提取结果...");return "";}//正在进行采集结果筛选public bool Filter(string result, string extractionRule, string dataColumn, System.Data.DataRow extractingResultRow){this.WriteLog("正在进行采集结果筛选...");return true;}//所需选项public RequiredOptions GetRequiredOptions(){this.WriteLog("所需选项...");return RequiredOptions.None;}public Form GetSettingForm(string taskPath, string pluginPath, Bget.Plugin.BgetInformation bgetInfo){return new hx_Plug();}//获取代理public BgetWebProxy GetWebProxy(string requestingUrl, int retryTimes){this.WriteLog("获取代理...");return null;}//从数据库载入起始地址public string LoadStartingUrl(string template, ref int position, string cookie){this.WriteLog("从数据库载入起始地址...");return "http://www.sensite.cn";}//正在登录public string Login(string url){this.WriteLog("正在登录...");return "";}//选择下一层网址public StringCollection PickNextLayerUrls(string htmlText, string layer, string url, string cookie){return null;}//选择下一个网页网址public string PickNextPageUrl(string htmlText, string layer, string url, string cookie){return "";}//正在处理下载后的内容文件public void ProcessContentFile(string path, bool skipped){this.WriteLog("正在处理下载后的内容文件...");}//正在处理结果数据行public bool ProcessResultRow(System.Data.DataRow extractedResultRow){this.WriteLog("《红星关键字过滤插件 V1.0》");this.WriteLog(string.Format("过滤:{0}", extractedResultRow[0].ToString()));KeywordFilter keyFilter = new KeywordFilter();extractedResultRow[1] = keyFilter.On_Filter(extractedResultRow[1].ToString());return true;}//正在处理下载后的独立文件public string ProcessSingleFile(string path, string fileNamePrefix, bool skipped){this.WriteLog("正在处理下载后的独立文件...");return fileNamePrefix + Path.GetFileName(path);}//正在请求URLpublic string Visit(string url, byte[] postData, string layer, string cookie, string referer){this.WriteLog("正在请求URL: " + url);return "<html>test</html>";}public event LogEventHanlder Log;private void WriteLog(string message){if (this.Log != null){this.Log(this, new LogEventArgs(message));}}private void WriteLog(string message, int indent){if (this.Log != null){this.Log(this, new LogEventArgs(message, indent));}} }
}
具体实现功能代码:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Windows.Forms;namespace HX_Plug
{/// <summary>/// 文章内容过滤类/// </summary>public class KeywordFilter{private List<FilterStruct> _filter = new List<FilterStruct>();/// <summary>/// 构造函数,初始化关键字集合/// </summary>public KeywordFilter(){DataTable dt = new DataTable();using (DBase db = new DBase()){dt = db.GetDataTable("select oldValue,newValue from Filter");}if (dt != null){if (dt.Rows.Count != 0){for (int i = 0; i < dt.Rows.Count; i++){FilterStruct fil = new FilterStruct();fil.OldValue = dt.Rows[i][0].ToString();fil.NewValue = dt.Rows[i][1].ToString();_filter.Add(fil);}}}}/// <summary>/// 关键词过滤/// </summary>/// <param name="Content">内容</param>/// <returns>过滤后的内容</returns>public string On_Filter(string Content){Content = ReplaceKeyword(Content); //常规关键词过滤Content = SubContent(Content, 2000); //切割文章为指定长度Content = SpltParagraph(Content); //打乱句子if(Content != string.Empty)Content += "《红星关键字过滤系统V1.0》";return Content;}/// <summary>/// 过滤常规关键词/// </summary>/// <param name="Content">内容</param>/// <returns>过滤结果</returns>private string ReplaceKeyword(string Content){for (int i = 0; i < _filter.Count; i++){Content = Content.Replace(_filter[i].OldValue, _filter[i].NewValue);}return Content += _filter.Count.ToString();}/// <summary>/// 句子打乱/// </summary>/// <param name="Content">原始内容</param>/// <returns>打乱结果</returns>private string SpltParagraph(string Content){string[] Paragraph = Content.Split('。');string src = string.Empty;if (Paragraph.Length != 0 && Paragraph.Length > 5){//随即交换一部分文章以句号分割的段落Random r = new Random();for (int i = 0; i < Paragraph.Length / 20; i++){Paragraph = RandomParagraph(r.Next(Paragraph.Length), r.Next(Paragraph.Length), Paragraph);}//重新组合文章内容for (int i = 0; i < Paragraph.Length; i++){if (i == 0){string line = Paragraph[i].ToString();if (line.Length > 8){line = line.Replace(",", string.Empty);line = line.Replace("\"", string.Empty);line = line.Replace(",", string.Empty);line = line.Replace("“", string.Empty);line = line.Replace("”", string.Empty);line = line.Replace(" ", string.Empty);line = "<h3>" + line.Substring(0, 8) + "</h3>";}src += (line + "<p>" + Paragraph[i].ToString());}else if (i % 5 == 0){string line = Paragraph[i].ToString();if (line.Length > 8){line = line.Replace(",", string.Empty);line = line.Replace("\"", string.Empty);line = line.Replace(",", string.Empty);line = line.Replace("“", string.Empty);line = line.Replace("”", string.Empty);line = line.Replace(" ", string.Empty);line = "<h3>" + line.Substring(0, 8) + "</h3>";}src += ("。</p>" + line + "<p>" + Paragraph[i].ToString());}else{src += Paragraph[i].ToString();}}return src;}else{return Content;}}/// <summary>/// 随即交换文章内容/// </summary>/// <param name="start">起始交换处</param>/// <param name="end">结束交换处</param>/// <param name="Paragraph">段落集合</param>/// <returns>交换结果</returns>private string[] RandomParagraph(int start, int end, string[] Paragraph){if (start != end && start < Paragraph.Length && end < Paragraph.Length){string swap = string.Empty;swap = Paragraph[start].ToString();Paragraph[start] = Paragraph[end].ToString();Paragraph[end] = swap;return Paragraph;}else{return Paragraph;}}/// <summary>/// 切割文章为指定长度/// </summary>/// <param name="Content">文章内容</param>/// <param name="length">切割长度</param>/// <returns>切割结果</returns>private string SubContent(string Content, int length){if (Content.Length > length){return Content = Content.Substring(0, length);}else if (Content.Length < 300){return string.Empty;}else{return Content;}}}/// <summary>/// 关键词过滤数据结构/// </summary>public struct FilterStruct{/// <summary>/// 被替换的字符/// </summary>public string OldValue;/// <summary>/// 替换后的字符/// </summary>public string NewValue;}
}
数据库底层连接类:(我把这个类写成了个通用的DLL,N久都没换过了)
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;namespace HX_Plug
{/// <summary>///数据库基本操作类,提供Access数据库基本操作,生存于数据层/// </summary>public class DBase : IDisposable{/// <summary>/// 数据库是否打开成功标志。成功:True,失败False。/// </summary>public bool Is_OpenState = false;/// <summary>/// Access数据库连接字符串/// </summary>private string strOleConn;/// <summary>/// Access数据库连接对象/// </summary>private OleDbConnection oleConn;/// <summary>/// 构造函数,初始化数据库连接,但不打开数据库/// 使用步骤:1.构造对象。2.检测Is_OpenState是否打开成功。3.操作数据库。4.自动或手工释放资源/// </summary>public DBase(){strOleConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=User.mdb;"; //数据库连接字符串oleConn = new OleDbConnection(strOleConn); //实例化数据库连接对象Is_OpenState = Open(); //设置当前数据库打开的状态}/// <summary>/// 打开数据库/// </summary>/// <returns>数据库打开是否成功。</returns>private bool Open(){try{//如果当前连接状态为关闭状态,则打开数据库连接if (oleConn.State == ConnectionState.Closed){oleConn.Open();}return true;}catch{return false;}}/// <summary>/// 关闭数据库/// </summary>/// <returns>数据库打开是否成功。</returns>private bool Close(){try{//如果当前连接状态为打开状态,则关闭数据库连接if (oleConn.State == ConnectionState.Open){oleConn.Close();}return true;}catch{return false;}}/// <summary>/// 释放资源/// </summary>public void Dispose(){Close(); //关闭连接if (oleConn != null) //销毁对象{oleConn.Dispose();}}/// <summary>/// 析构函数,自动释放资源/// </summary>~DBase(){Dispose(); //释放资源}/// <summary>/// 执行SqlCommand语句,返回一个DataTable/// </summary>/// <param name="sqlCommand">SqlCommand语句</param>/// <returns>执行成功返回DataTable对象,否则返回Null</returns>public DataTable GetDataTable(string sqlCommand){DataSet ds = new DataSet();try{OleDbDataAdapter da = new OleDbDataAdapter(sqlCommand, oleConn);da.Fill(ds);int i = ds.Tables[0].Rows.Count;return ds.Tables[0];}catch{return null;}}void IDisposable.Dispose(){}}
}
悲哀,没有找到上传附件发功能。需要的话给我留个消息吧,我给你发过去。
附修改:
由于上网时间比较少,急需源代码的童鞋可以直接发送邮件To:549015917@qq.com;注明标题和内容,这样可以得到最快的处理!
网络神采关键词过滤NET插件相关推荐
- 对文本内容进行关键词过滤
网络中的信息有一些是有害的,因此我们经常需要对网络信息进行屏蔽或过滤.过滤信息一般有禁止输入.信息替换(如用"*"替换).直接删除等方式.这些信息过滤业务的处理一般在后台完成,如果 ...
- dedeCMS如何进行关键词过滤替换和屏蔽非法词汇?
dedeCMS系统模板安装完毕之后,如何进行非法词汇的屏蔽,以及关键词过滤替换呢? 一.所需修改文件路径: C:\wamp64\www\install\config.cache.inc.php 二.对 ...
- 企业做网络推广关键词设置的几点个人看法
企业做网络推广关键词设置的几点个人看法 A 如何选择关键词 怎样挑选正确的关键词 怎样挑选关键词是网络推广中最重要的步骤之中的一个,同一时候也是大多数企业在做网络推广时候easy忽视的问题.都觉得 ...
- [Vue]实现交换布局,输入关键词过滤列表内容
思路: 实现列表布局(list)与网格布局(grid)交换 画好页面后,给搜索框进行数据绑定 给旁边的两个用于切换布局的按钮添加点击事件 下面的橙色和蓝色分别对应list和grid布局,设置v-if ...
- XCTF-攻防世界CTF平台-Web类——14、supersqli(SQL注入、关键词过滤)
目录标题 方法一.堆叠注入 1.rename修改表名和alter change修改列名 2.rename修改表名和alter add添加列名 方法二.handler语句 方法三.预编译 打开题目地址 ...
- PHP7.2使用扩展trie-filter进行关键词过滤
关键词过滤扩展,用于检查一段文本中是否出现关键词,基于Double-Array Trie 树实现 一.安装libiconv 这个是libdatrie的依赖项 PHP7.2的用法: wget http: ...
- 如何实现一个高效的关键词过滤功能?——DFA算法
文章目录 一.前言 二.何为DFA算法 三.DFA算法优化关键词过滤 四.java代码实现 五.总结 一.前言 有一个关键词库,此时需要检索一段文本中是否出现词库中的关键词,该如何实现? 小白回答:将 ...
- SQL注入绕过关键词过滤的小技巧及原理(union select为例)
本文以联合查询关键字union select为例讲解绕过关键词过滤的一些方法.之所以了解绕过,关键是发现sqlmap有时候真的是不靠谱,只能指定命令跑.有一些简单过滤很容易绕过却不能检 ...
- SQL注入防御之二——注入关键词过滤(PHP)
SQL Injection:就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令. 概述 欢迎来到本人的SQL注入防御系列的第二篇文章, ...
- C++ 关键词过滤,屏蔽应用
关键词过滤–延伸多关键词过滤(业务需求) 首先最笨的方法是每个关键词完整的存放在一个容器中,文本内容解析完传过来的时候进行过滤,那么这种方法要对每一个关键词做一次完整比对,不相同则比较下一组,这种最坏 ...
最新文章
- Aasp.net前台调用后台cs变量
- JMSTemplate发送消息
- springboot 问题总结
- onclick函数的导包问题
- Scala模式匹配:类型匹配
- springMVC通过spring.xml对属性注入bean值(工厂模式)
- P2756,ssl2601-飞行员配对问题【网络流24题,最大匹配,dinic】
- zk ui_高级ZK:异步UI更新和后台处理–第1部分
- kafka 如何做到1秒发布百万级条消息?
- 领域驱动 开源项目_在开源领域建立职业的建议
- linux 中文乱码 转png_使用pdfBox实现pdf转图片,解决中文方块乱码等问题
- 用于解决SQL2014安装时出现需要更新vs2010的问题
- iso27001标准动态
- java 仓库管理系统源码
- 2011年6个微博营销趋势
- 学计算机笔记本屏幕多大,笔记本屏幕尺寸有哪些 2分钟让你全整明白【详解】...
- LInux 实训二记录
- 吐槽微软,远离微软!
- Simulink模型生成C语言
- windows下MYSQL 5.7 64位绿色版 安装步骤