代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
获取搜索引擎关键字
作者:
dezai
/ 发布于
2014/6/20
/
481
C#获取搜索引擎关键字 using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Text; using System.Text.RegularExpressions; public partial class Default2 : System.Web.UI.Page { private void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack) Response.Write(SearchKey("=")); } private string[][] _Enginers = new string[][] { new string[]{"google","utf8","q"}, new string[]{"baidu","gb2312","wd"}, new string[]{"yahoo","utf8","p"}, new string[]{"yisou","utf8","search"}, new string[]{"live","utf8","q"}, new string[]{"tom","gb2312","word"}, new string[]{"163","gb2312","q"}, new string[]{"iask","gb2312","k"}, new string[]{"soso","gb2312","w"}, new string[]{"sogou","gb2312","query"}, new string[]{"zhongsou","gb2312","w"}, new string[]{"3721","gb2312","p"}, new string[]{"openfind","utf8","q"}, new string[]{"alltheweb","utf8","q"}, new string[]{"lycos","utf8","query"}, new string[]{"onseek","utf8","q"} }; //搜索引擎名称 private string _EngineName = ""; public string EngineName { get { return _EngineName; } } private string _Coding = "utf8"; public string Coding { get { return _Coding; } } private string _RegexWord = ""; public string RegexWord { get { return _RegexWord; } } private string _Regex = @"("; //搜索引擎关键字 public void EngineRegEx(string myString) { for (int i = 0, j = _Enginers.Length; i < j; i++) if (myString.Contains(_Enginers[i][0])) _EngineName = _Enginers[i][0]; _Coding = _Enginers[i][1]; _RegexWord = _Enginers[i][2]; _Regex += _EngineName + @".+.*[?/&]" + _RegexWord + @"[=:])(?<key>[^&]*)"; break; } //得到搜索引擎关键字 public string SearchKey(string myString) { EngineRegEx(myString.ToLower()); if (_EngineName != "") { Regex myReg = new Regex(_Regex, RegexOptions.IgnoreCase); Match matche = myReg.Match(myString); myString = matche.Groups["key"].Value; myString = myString.Replace("+", " "); if (_Coding == "gb2312") myString = GetUTF8String(myString); else myString = Uri.UnescapeDataString(myString); } return myString; } //整句转码 public string GetUTF8String(string myString) { Regex myReg = new Regex("(?<key>%..%..)", RegexOptions.IgnoreCase); MatchCollection matches = myReg.Matches(myString); string myWord; for (int i = 0, j = matches.Count; i < j; i++) { myWord = matches[i].Groups["key"].Value.ToString(); myString = myString.Replace(myWord, GB2312ToUTF8(myWord)); return myString; } } //单字GB2312转UTF8 URL编码 public string GB2312ToUTF8(string myString) { string[] myWord = myString.Split("%"); byte[] myByte = new byte[] { Convert.ToByte(myWord[1], 16), Convert.ToByte(myWord[2], 16) }; Encoding GB = Encoding.GetEncoding("GB2312"); Encoding U8 = Encoding.UTF8; myByte = Encoding.Convert(GB, U8, myByte); char[] Chars = new char[U8.GetCharCount(myByte, 0, myByte.Length)]; U8.GetChars(myByte, 0, myByte.Length, Chars, 0); return new string(Chars); } //判断否为搜索引擎爬虫,并返回其类型 public string isCrawler(string SystemInfo) { string[] BotList = new string[] { "Google", "Baidu", "MSN", "Yahoo", "TMCrawler", "iask", "Sogou" }; foreach (string Bot in BotList) if (SystemInfo.ToLower().Contains(Bot.ToLower())) return Bot; return "null"; } }
试试其它关键字
搜索引擎
关键字
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
dezai
贡献的其它代码
(
1065
)
.
双色球
.
列出所有物理网络适配器
.
快乐数的 Python 实现
.
计算当月还剩天数
.
猜属相
.
二十四小时时钟
.
每日一语
.
很酷的日历
.
超长日历表单
.
最简单的时钟
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3