using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web; namespace HbTui.Portal
{
public class SearchKeyWord
{
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[]{"","gb2312","q"},
new string[]{"iask","gb2312","k"},
new string[]{"soso","gb2312","w"},
new string[]{"sogou","gb2312","query"},
new string[]{"zhongsou","gb2312","w"},
new string[]{"","gb2312","p"},
new string[]{"openfind","utf8","q"},
new string[]{"alltheweb","utf8","q"},
new string[]{"lycos","utf8","query"},
new string[]{"youdao","utf8","q"},
new string[]{"onseek","utf8","q"},
new string[]{"jike","utf8","q"}
}; //搜索引擎名称
private string _EngineName = string.Empty;
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 = , j = _Enginers.Length; i < j; i++)
{
if (myString.Contains(_Enginers[i][]))
{
_EngineName = _Enginers[i][];
_Coding = _Enginers[i][];
_RegexWord = _Enginers[i][];
_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 = , 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[], ), Convert.ToByte(myWord[], ) };
Encoding GB = Encoding.GetEncoding("GB2312");
Encoding U8 = Encoding.UTF8;
myByte = Encoding.Convert(GB, U8, myByte);
char[] Chars = new char[U8.GetCharCount(myByte, , myByte.Length)];
U8.GetChars(myByte, , myByte.Length, Chars, );
return new string(Chars);
} //判断否为搜索引擎爬虫,并返回其类型
public string isCrawler(string SystemInfo)
{
string[] BotList = new string[] { "Google", "Baidu", "yisou", "MSN", "Yahoo", "live", "tom", "", "TMCrawler", "iask", "Sogou", "soso", "youdao", "zhongsou", "", "openfind", "alltheweb", "lycos", "bing", "" };
foreach (string Bot in BotList)
{
if (SystemInfo.ToLower().Contains(Bot.ToLower()))
{
return Bot;
}
}
return "null";
}
public bool IsSearchEnginesGet(string str)
{
string[] strArray = new string[] { "Google", "Baidu", "yisou", "MSN", "Yahoo", "live", "tom", "", "TMCrawler", "iask",
"Sogou", "soso", "youdao", "zhongsou", "", "openfind","alltheweb", "lycos", "bing", ""};
str = str.ToLower();
for (int i = ; i < strArray.Length; i++)
{
if (str.IndexOf(strArray[i].ToLower()) >= )
{
return true;
}
}
return false;
}
}
}

C# 分析搜索引擎url 得到搜索关键字的更多相关文章

  1. C#分析搜索引擎URL得到搜索关键字,并判断页面停留时间以及来源页面

    前台代码: var start; var end; var state; var lasturl = document.referrer; start = new Date($.ajax({ asyn ...

  2. 百度搜索URL参数 搜索关键字

    http://www.baidu.com/s?wd=关键字 wd(Keyword):查询的关键词: http://www.baidu.com/s?wd=关键字&cl=3 cl(Class):搜 ...

  3. 搜索引擎case︱从搜索序列文本看高端商务车︱统计之都

    朱雪宁(北京大学光华管理学院)               王汉生(北京大学光华管理学院) 摘要:本文对100万搜索引擎用户的13亿搜索序列文本进行探索分析,对高端车用户以及商学院人群做了描述对比,并 ...

  4. google 搜索关键字技巧

    google 搜索关键字技巧 来源  https://www.cnblogs.com/qiudabai/articles/9143328.html inurl: 用于搜索网页上包含的URL. 这个语法 ...

  5. Django项目:CRM(客户关系管理系统)--26--18PerfectCRM实现King_admin搜索关键字

    search_fields = ('name','qq',) 登陆密码设置参考 http://www.cnblogs.com/ujq3/p/8553784.html search_fields = ( ...

  6. 在 Angular 中实现搜索关键字高亮

    在 Angular 中,我们不应该试图直接修改 DOM 的内容,当需要更新 DOM 内容的时候,应该修改的其实是我们的数据模型,也就是 $scope 中的数据,Angular 会帮助我们将修改之后的数 ...

  7. 仿百度壁纸客户端(五)——实现搜索动画GestureDetector手势识别,动态更新搜索关键字

    仿百度壁纸客户端(五)--实现搜索动画GestureDetector手势识别,动态更新搜索关键字 百度壁纸系列 仿百度壁纸客户端(一)--主框架搭建,自定义Tab + ViewPager + Frag ...

  8. Elasticsearch 基于 URL 的搜索请求

    背景 Elasticsearch 不像关系型数据库,没有简易的 SQL 用来查询数据,只能通过调用 RESTful API 实现查询.大体上查询分为两种,基于 URL 的和基于请求主体的.基于 URL ...

  9. 帝国cms搜索关键字调用标签(showsearch)怎么用

    前面ytkah介绍了如何让帝国CMS7.2搜索模板支持动态标签调用,现在我们来说说怎么调用帝国cms搜索关键字调用标签(showsearch).在帝国cms后台那边的使用方法:[showsearch] ...

随机推荐

  1. JAVA笔记(一)super and this

    http://zhangjunhd.blog.51cto.com/113473/20531 总结关键字this与super用法. author: ZJ 07-3-12 Blog: [url]http: ...

  2. 寒冰王座(hd1248)

    寒冰王座 Problem Description 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票(记住,只有一张钞票),为了防止自己在战斗中频繁的死掉,他决定给自己买一些道具,于是他来到了地精商店 ...

  3. php5.5以上的版本 开启curl

    对于php5.5以上的版本开启方法,需要libeay32.dll.ssleay32.dll.libssh2.dll三个文件拷备到C:\Windows目录下,php.ini中 扩展开启,重启apache ...

  4. Seafile 推出 “分布式文件同步技术” 打造的私有云服务

    近两年来 Dropbox 等云储存服务迅速窜红,各大巨头纷纷推出自家的云储存服务(苹果的 iCloud, 微软的 SkyDrive, Google 即将推出的 GDrive),国内也有类似的服务(金山 ...

  5. 可以供MFC调用的,QT实现的DLL(qtwinmigrate实现)

    MFC和QT的消息循环机制不同,所以,要让QT写的DLL可以供MFC调用,要做一点特殊的处理 #include <qmfcapp.h> #include <qwinwidget.h& ...

  6. xcode 5与ios 7的屏幕适配问题

    #define DEVICE_IS_IPHONE5 ([[UIScreen mainScreen] bounds].size.height == 568) float height = DEVICE_ ...

  7. codeforces gym 100187M Heaviside Function

    //大概就是没想起来怎么做 解法:首先观察seitan方程,发现我们要找的是满足seitan(si*x-ai)=1的方程数,即si*x-ai>=0的方程数,因为si=1 or -1,于是分类讨论 ...

  8. hdu 2665 Kth number_划分树

    题意:求区间[a,b]的第k大 因为多次询问要用到划分树 #include <iostream> #include<cstdio> #include<algorithm& ...

  9. 在flash builder 4.6中使用ant编译项目的详细过程

    首先要准备APACHE ANT,目前是1.9.2版 可以去这里下载:http://ant.apache.org/bindownload.cgi?Preferred=http://labs.renren ...

  10. Java面向对象知识点精华