濮阳杆衣贸易有限公司

主頁 > 知識庫 > java asp分析各種搜索引擎的關(guān)鍵字,自動識別url 中關(guān)鍵字的編碼

java asp分析各種搜索引擎的關(guān)鍵字,自動識別url 中關(guān)鍵字的編碼

熱門標(biāo)簽:揭陽外呼系統(tǒng)公司 鄭州中國移動400電話申請 無錫電銷機器人銷售 招聘信息 地圖標(biāo)注植物名稱 福建ai電銷機器人加盟公司 熱血傳奇沃瑪森林地圖標(biāo)注 地圖標(biāo)注審核工作怎么樣注冊 去哪里辦卡 南召400電話辦理資費
所以必須要通過編碼后的關(guān)鍵字,例如“解析關(guān)鍵字編碼”在google里面輸入搜索,得到編碼后的“%E8%A7%A3%E6%9E%90%E5%85%B3%E9%94%AE%E5%AD%97%E7%BC%96%E7%A0%81”
1.從以上地址中解析出關(guān)鍵字部分。
2.通過編碼后的關(guān)鍵字獲取編碼時的編碼名稱(如:gbk,utf-8等等)
3.用URLdecode(keywords,encodeCode)來解碼得到對應(yīng)的關(guān)鍵字。
以下是java代碼的實現(xiàn):
復(fù)制代碼 代碼如下:

package test;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ParseURLKeyword {
public static void main(String[] args) {
String url = "http://www.google.co.kr/search?hl=enq=%ED%95%9C%EA%B5%AD%EC%96%B4+btnG=Google+Searchaq=foq=";
System.out.println(ParseURLKeyword.getKeyword(url));
System.out.println("");
url = "http://www.google.cn/search?q=%E6%8F%90%E5%8F%96+%E6%90%9C%E7%B4%A2%E5%BC%95%E6%93%8E+%E5%85%B3%E9%94%AE%E5%AD%97hl=zh-CNnewwindow=1sa=2";
System.out.println(ParseURLKeyword.getKeyword(url));
System.out.println("");
url = "http://www.google.com.tw/search?hl=zh-CNq=%E6%B9%98%E9%8B%BC%E4%B8%AD%E5%9C%8B%E9%A6%99%E7%85%99btnG=Google+%E6%90%9C%E7%B4%A2aq=foq=";
System.out.println(ParseURLKeyword.getKeyword(url));
System.out.println("");
url = "http://www.baidu.com/s?wd=%D6%D0%87%F8%D3%D0%BE%80%D8%9F%C8%CE%B9%AB%CB%BE";
System.out.println(ParseURLKeyword.getKeyword(url));
System.out.println("");
url = "http://www.baidu.com/s?wd=%C6%F3%D2%B5%CD%C6%B9%E3";
System.out.println(ParseURLKeyword.getKeyword(url));
System.out.println("");
}
public static String getKeyword(String url){
String keywordReg = "(?:yahoo.+?[\\?|]p=|openfind.+?query=|google.+?q=|lycos.+?query=|onseek.+?keyword=|search\\.tom.+?word=|search\\.qq\\.com.+?word=|zhongsou\\.com.+?word=|search\\.msn\\.com.+?q=|yisou\\.com.+?p=|sina.+?word=|sina.+?query=|sina.+?_searchkey=|sohu.+?word=|sohu.+?key_word=|sohu.+?query=|163.+?q=|baidu.+?wd=|soso.+?w=|3721\\.com.+?p=|Alltheweb.+?q=)([^]*)";
String encodeReg = "^(?:[\\x00-\\x7f]|[\\xfc-\\xff][\\x80-\\xbf]{5}|[\\xf8-\\xfb][\\x80-\\xbf]{4}|[\\xf0-\\xf7][\\x80-\\xbf]{3}|[\\xe0-\\xef][\\x80-\\xbf]{2}|[\\xc0-\\xdf][\\x80-\\xbf])+$";
Pattern keywordPatt = Pattern.compile(keywordReg);
StringBuffer keyword = new StringBuffer(20);
Matcher keywordMat = keywordPatt.matcher(url);
while (keywordMat.find()) {
keywordMat.appendReplacement(keyword, "$1");
}
if (!keyword.toString().equals("")){
String keywordsTmp = keyword.toString().replace("http://www.", "");
Pattern encodePatt = Pattern.compile(encodeReg);
String unescapeString = ParseURLKeyword.unescape(keywordsTmp);
Matcher encodeMat = encodePatt.matcher(unescapeString);
String encodeString = "gbk";
if (encodeMat.matches()) encodeString = "utf-8";
try {
return URLDecoder.decode(keywordsTmp, encodeString);
} catch (UnsupportedEncodingException e) {
return "";
}
}
return "";
}
public static String unescape(String src) {
StringBuffer tmp = new StringBuffer();
tmp.ensureCapacity(src.length());
int lastPos = 0, pos = 0;
char ch;
while (lastPos src.length()) {
pos = src.indexOf("%", lastPos);
if (pos == lastPos) {
if (src.charAt(pos + 1) == 'u') {
ch = (char) Integer.parseInt(src.substring(pos + 2, pos + 6), 16);
tmp.append(ch);
lastPos = pos + 6;
} else {
ch = (char) Integer.parseInt(src.substring(pos + 1, pos + 3), 16);
tmp.append(ch);
lastPos = pos + 3;
}
} else {
if (pos == -1) {
tmp.append(src.substring(lastPos));
lastPos = src.length();
} else {
tmp.append(src.substring(lastPos, pos));
lastPos = pos;
}
}
}
return tmp.toString();
}
}

以下是Asp的實現(xiàn)代碼:
復(fù)制代碼 代碼如下:

Function DecodeURI(s)
s = UnEscape(s)
Dim reg, cs
cs = "GBK"
Set reg = New RegExp
reg.Pattern = "^(?:[\x00-\x7f]|[\xfc-\xff][\x80-\xbf]{5}|[\xf8-\xfb][\x80-\xbf]{4}|[\xf0-\xf7][\x80-\xbf]{3}|[\xe0-\xef][\x80-\xbf]{2}|[\xc0-\xdf][\x80-\xbf])+$"
If reg.Test(s) Then cs = "UTF-8"
Set reg = Nothing
Dim sm
Set sm = CreateObject("ADODB.Stream")
With sm
.Type = 2
.Mode = 3
.Open
.CharSet = "iso-8859-1"
.WriteText s
.Position = 0
.CharSet = cs
DecodeURI = .ReadText(-1)
.Close
End With
Set sm = Nothing
End Function
Response.Write DecodeURI("%B8%A7%CB%B3%C7%E0%CB%C9%D2%A9%D2%B5")
Response.Write DecodeURI("%E6%8A%9A%E9%A1%BA%E9%9D%92%E6%9D%BE%E8%8D%AF%E4%B8%9A")
您可能感興趣的文章:
  • java識別一篇文章中某單詞出現(xiàn)個數(shù)的方法
  • Java基于直方圖應(yīng)用的相似圖片識別實例
  • Java進階教程之運行時類型識別RTTI機制
  • java網(wǎng)絡(luò)編程之識別示例 獲取主機網(wǎng)絡(luò)接口列表
  • Java實現(xiàn)Shazam聲音識別算法的實例代碼

標(biāo)簽:桂林 鹽城 南昌 黔南 文山 東莞 宣城 景德鎮(zhèn)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《java asp分析各種搜索引擎的關(guān)鍵字,自動識別url 中關(guān)鍵字的編碼》,本文關(guān)鍵詞  java,asp,分析,各種,搜索引擎,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《java asp分析各種搜索引擎的關(guān)鍵字,自動識別url 中關(guān)鍵字的編碼》相關(guān)的同類信息!
  • 本頁收集關(guān)于java asp分析各種搜索引擎的關(guān)鍵字,自動識別url 中關(guān)鍵字的編碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    苍溪县| 社会| 松滋市| 达拉特旗| 望奎县| 尚义县| 河池市| 长宁区| 沧源| 商南县| 石屏县| 三明市| 长阳| 仪陇县| 图片| 修武县| 旬邑县| 五寨县| 莱州市| 裕民县| 乌拉特中旗| 胶南市| 韶山市| 城市| 唐海县| 饶阳县| 沾化县| 滨州市| 华安县| 临武县| 石楼县| 西城区| 开平市| 江孜县| 湘潭县| 常山县| 策勒县| 永定县| 蓬安县| 景泰县| 法库县|