用百度搜索时百度把搜索的中文关键字进行了gb231编码,用js如何把这个gb2312编码还原成汉字
解决方案 »
- wml+aspx的wap网页登录界面,验证后不能正常跳转(路径绝对没问题,用手机验证的时候,提示handler1.ashx中有语法错误),请大神看看。急!!
- control.parent与control.namingcontainer有什么区别??
- 如何通过javascript改变表格的列宽???
- 做上传图片 报找不到类型命名空间名称 Drawimagemark (是否缺少using指令或程序集)
- 用代码改变水晶报表组字段的排序方式.
- asp.net网站生成静态页面
- 请问ASP.net在实际开发项目中的步骤是什么?还在ASP.net的界面如何处理,真的就是拖动就行了吗?
- 新手提问,我初学,按照书上的步骤写例子,遇到了不能在localhost上新建web应用程序的问题
- 数据库连接的释放资源问题?
- 在asp.net中通过url传递数据出现数据丢失是怎么一回事?
- 秀新版Vs2005的日期控件
- ASP.Net button点击后不切换到事件处理代码
Server.UrlEncode("试试")
lz自己试吧,应该是2个中的一个,好像是UrlEncode...
<%
' 从URL中获取关键词
function findKeystr(urlstr)
dim regEx,vKey,vP,findKeystr1
findkeystr=""
vP = "(?:yahoo.+?[\?|&]p=|openfind.+&q=|google.+[\?|&]q=|lycos.+?query=|aol.+?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=|3721\.com.+?name=|Alltheweb.+?q=)([^&]*)"
set regEx=new regexp
regEx.Global = true
regEx.IgnoreCase = true
regEx.Pattern = vP set Matches = regEx.Execute(urlstr)
for each Match in Matches
' 没有使用subMatches是因为有的服务器可能并没有安装VBS5.5版本
findKeystr1 = regEx.replace(Match.value,"$1")
next if findKeystr1<> "" then
findkeystr=lcase(decodeURI(findkeystr1))
if findkeystr = "undefined" then
findkeystr = URLDecode(findKeystr1)
end if
end if
end function' 解开URL编码的函数(这是别人写的,我查到的地方标注为: 来源: CSDN 作者: dyydyy )
Function URLDecode(enStr)
dim deStr
dim c,i,v
deStr=""
for i=1 to len(enStr)
c=Mid(enStr,i,1)
if c="%" then
v=eval("&h"+Mid(enStr,i+1,2))
if v<128 then
deStr=deStr&chr(v)
i=i+2
else
if isvalidhex(mid(enstr,i,3)) then
if isvalidhex(mid(enstr,i+3,3)) then
v=eval("&h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2))
deStr=deStr&chr(v)
i=i+5
else
v=eval("&h"+Mid(enStr,i+1,2)+cstr(hex(asc(Mid(enStr,i+3,1)))))
deStr=deStr&chr(v)
i=i+3
end if
else
destr=destr&c
end if
end if
else
if c="+" then
deStr=deStr&" "
else
deStr=deStr&c
end if
end if
next
URLDecode=deStr
end function
function isvalidhex(str)
isvalidhex=true
str=ucase(str)
if len(str)<>3 then isvalidhex=false:exit function
if left(str,1)<>"%" then isvalidhex=false:exit function
c=mid(str,2,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
c=mid(str,3,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
end functionResponse.write findKeystr("http://www.google.com/search?hl=zh-CN&q=%E4%B8%AD%E5%9B%BDe%E5%BA%B7&btnG=Google+%E6%90%9C%E7%B4%A2&lr=")%>
<script language="javascript" runat="server" type="text/javascript">
//解码URI
function decodeURI(furl){
var a=furl;
try{return decodeURIComponent(a)}catch(e){return 'undefined'};
return '';
}
</script>
--Stolen from Jiang Statistics
function encode(str){
return escape(str);
}function decode(str){
return unescape(str);
}
</script>
现在做一个网站流量计数器,发现以下问题: 我在提取来源页面地址,发现google过来的关键字存放数据库时编码不正常,而百度过来的是正常的。 例如从百度过来的:http://www.baidu.com/s?wd=%C4%E3%BA%C3&cl=3 关键字:%C4%E3%BA%C3 解码后存放数据库:你好 这个是正常的 而Google过来的:http://www.google.cn/search?complete=1&hl=zh-CN&q=%E4%BD%A0%E5%A5%BD&meta= 关键字:%E4%BD%A0%E5%A5%BD 存放数据库就是乱码。 我知道google是采用utf-8格式编码的百度应该是gb2312的,我在webconfig里设置的格式是GB2312后来我把webconfig 编码格式改成为utf-8结果就相反了, google上的又能正确转换了,而百度上的就不行了。 请问各位大哥有什么方法帮小弟解决这个问题吗?谢谢啦你获取路径的时候先把路径编码成你想要的编码方式 然后再获取关键字 HttpUtility.UrlEncode(路径System.Text.Encoding.GetEncoding("gb2312")Request.Params["keyWord"].ToString() 在这个时候已经被解码了没办法用 HttpUtility.UrlEncode(Request.Params["keyWord"].ToString()System.Text.Encoding.GetEncoding("gb2312")System.Collections.Specialized.NameValueCollection requestUrl = HttpUtility.ParseQueryString(Request.Url.Query Encoding.GetEncoding("gb2312")); String baiduKeyword = requestUrl["keyword"]; 或者 Response.ContentEncoding 先使用GB2312,获取后再转回UTF-8
前面不是已经讲了吗?
我在百度中输入:中
http://www.baidu.com/s?wd=%D6%D0
这样输出:中
Response.Write(Server.UrlEncode("中"));
得到%e4%b8%ad js的escape同样不行。
Response.Write(Server.UrlEncode("中",Encoding.UTF8));
这个方法有错误,谁知道的正确的方法,试一试百度用得什么编码方式。