# coding=gbk
import urllib
import re
def decodeQuery(query):
lowStr = query.lower()
if lowStr.find("%u")!=-1:
t = re.compile(r"%u([0-9a-f]{2})([0-9a-f]{2})",re.IGNORECASE)
matchList = t.findall(lowStr)
for match in matchList:
hex = match[0]+match[1]
chr = hex.decode("hex")
try:
dechr = chr.decode("utf-16be").encode("gbk")
lowStr = lowStr.replace("%u"+hex,dechr)
except:
lowStr = lowStr.replace("%u"+hex,"?")
else:
lowStr = lowStr.replace("\\x","%")
try:
deQuery = urllib.unquote(lowStr)
except:
deQuery = lowStr
return deQuery
decode uigs中的查询词
最新推荐文章于 2022-05-31 17:02:47 发布