盾怪网教程:是一个免费提供流行杀毒软件教程、在线学习分享的学习平台!

asp完成关键词取得(各搜索引擎,gb2312及utf-8)

时间:2024/12/1作者:未知来源:盾怪网教程人气:

[摘要]baidu.*?w=([^&]*))" Set a = re.Execute(RefererUrl) If a.Count>0 then Set b = a(a.Co...
baidu.*?w=([^&]*))"
  Set a = re.Execute(RefererUrl)
  If a.Count>0 then
   Set b = a(a.Count-1).SubMatches
   For j=1 to b.Count
    If Len(b(j))>0 then
     if instr(1,RefererUrl,"google",1) then
       GetSearchKeyword=Trim(U8Decode(b(j)))
      elseif instr(1,refererurl,"yahoo",1) then
       GetSearchKeyword=Trim(U8Decode(b(j)))
      elseif instr(1,refererurl,"yisou",1) then
       GetSearchKeyword=Trim(getkey(b(j)))
      elseif instr(1,refererurl,"3721",1) then
       GetSearchKeyword=Trim(getkey(b(j)))
      else
       GetSearchKeyword=Trim(getkey(b(j)))
     end if
     Exit Function
    end if
   Next
  End If
  if err then
  err.clear
  GetSearchKeyword = RefererUrl
  else
  GetSearchKeyword = "" 
  end if 
 End Function


 Function URLEncoding(vstrIn)
  dim strReturn,i,thischr
    strReturn = ""
    For i = 1 To Len(vstrIn)
        ThisChr = Mid(vStrIn,i,1)
        If Abs(Asc(ThisChr)) < &HFF Then
            strReturn = strReturn & ThisChr
        Else
            innerCode = Asc(ThisChr)
            If innerCode < 0 Then
                innerCode = innerCode + &H10000
            End If
            Hight8 = (innerCode  And &HFF00)\ &HFF
            Low8 = innerCode And &HFF
            strReturn = strReturn & "%" & Hex(Hight8) &  "%" & Hex(Low8)
        End If
    Next
    URLEncoding = strReturn
End Function
function getkey(key)
dim oReq
set oReq = CreateObject("MSXML2.XMLHTTP")
oReq.open "POST","http://"&WebUrl&"/system/ShowGb2312XML.asp?a="&key,false
oReq.send
getkey=UTF2GB(oReq.responseText)
end function
function chinese2unicode(Str)
  dim i
  dim Str_one
  dim Str_unicode
  for i=1 to len(Str)
    Str_one=Mid(Str,i,1)
    Str_unicode=Str_unicode&chr(38)
    Str_unicode=Str_unicode&chr(35)
    Str_unicode=Str_unicode&chr(120)
    Str_unicode=Str_unicode& Hex(ascw(Str_one))
    Str_unicode=Str_unicode&chr(59)
  next
  Response.Write Str_unicode
end function    
 
function UTF2GB(UTFStr)
Dim dig,GBSTR
    for Dig=1 to len(UTFStr)
        if mid(UTFStr,Dig,1)="%" then
            if len(UTFStr) >= Dig+8 then
                GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9))
                Dig=Dig+8
            else
                GBStr=GBStr & mid(UTFStr,Dig,1)
            end if
        else
            GBStr=GBStr & mid(UTFStr,Dig,1)
        end if
    next
    UTF2GB=GBStr
end function


function ConvChinese(x)
dim a,i,j,DigS,Unicode
    A=split(mid(x,2),"%")
    i=0
    j=0
   
    for i=0 to ubound(A)
        A(i)=c16to2(A(i))
    next
       
    for i=0 to ubound(A)-1
        DigS=instr(A(i),"0")
        Unicode=""
        for j=1 to DigS-1
            if j=1 then
                A(i)=right(A(i),len(A(i))-DigS)
                Unicode=Unicode & A(i)
            else
                i=i+1
                A(i)=right(A(i),len(A(i))-2)
                Unicode=Unicode & A(i)
            end if
        next
       
        if len(c2to16(Unicode))=4 then
            ConvChinese=ConvChinese & chrw(int("&H" & c2to16(Unicode)))
        else
            ConvChinese=ConvChinese & chr(int("&H" & c2to16(Unicode)))
        end if
    next
end function

function U8Decode(enStr)
  '输入一堆有%分隔的字符串,先分成数组,根据utf8规则来判断补齐规则
  '输入:关 E5 85 B3  键  E9 94 AE 字   E5 AD 97
  '输出:关 B9D8  键  BCFC 字   D7D6
  dim c,i,i2,v,deStr,WeiS

  for i=1 to len(enStr)
    c=Mid(enStr,i,1)
    if c="%" then
      v=c16to2(Mid(enStr,i+1,2))
      '判断第一次出现0的位置,
      '可能是1(单字节),3(3-1字节),4,5,6,7不可能是2和大于7
      '理论上到7,实际不会超过3。
      WeiS=instr(v,"0")
      v=right(v,len(v)-WeiS)'第一个去掉最左边的WeiS个
      i=i+3
      for i2=2 to WeiS-1
        c=c16to2(Mid(enStr,i+1,2))
        c=right(c,len(c)-2)'其余去掉最左边的两个
        v=v & c
        i=i+3
      next
      if len(c2to16(v)) =4 then
        deStr=deStr & chrw(c2to10(v))
      else
        deStr=deStr & chr(c2to10(v))
      end if
      i=i-1
    else
      if c="+" then
        deStr=deStr&" "
      else
        deStr=deStr&c
      end if
    end if
  next
  U8Decode = deStr
end function

function c16to2(x)
 '这个函数是用来转换16进制到2进制的,可以是任何长度的,一般转换UTF-8的时候是两个长度,比如A9
 '比如:输入“C2”,转化成“11000010”,其中1100是"c"是10进制的12(1100),那么2(10)不足4位要补齐成(0010)。
 dim tempstr
 dim i:i=0'临时的指针

 for i=1 to len(trim(x))
  tempstr= c10to2(cint(int("&h" & mid(x,i,1))))
  do while len(tempstr)<4
   tempstr="0" & tempstr'如果不足4位那么补齐4位数
  loop
  c16to2=c16to2 & tempstr
 next
end function

function c2to16(x)
  '2进制到16进制的转换,每4个0或1转换成一个16进制字母,输入长度当然不可能不是4的倍数了

  dim i:i=1'临时的指针
  for i=1 to len(x)  step 4
   c2to16=c2to16 & hex(c2to10(mid(x,i,4)))
  next
end function

function c2to10(x)
  '单纯的2进制到10进制的转换,不考虑转16进制所需要的4位前零补齐。
  '因为这个函数很有用!以后也会用到,做过通讯和硬件的人应该知道。
  '这里用字符串代表二进制
   c2to10=0
   if x="0" then exit function'如果是0的话直接得0就完事
   dim i:i=0'临时的指针
   for i= 0 to len(x) -1'否则利用8421码计算,这个从我最开始学计算机的时候就会,好怀念当初教我们的谢道建老先生啊!
    if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i)
   next
end function

function c10to2(x)
'10进制到2进制的转换
  dim sign, result
  result = ""
  '符号
  sign = sgn(x)
  x = abs(x)
  if x = 0 then
    c10to2 = 0
    exit function
  end if
  do until x = "0"
    result = result & (x mod 2)
    x = x \ 2
  loop
  result = strReverse(result)
  if sign = -1 then
    c10to2 = "-" & result
  else
    c10to2 = result
  end if
end function

function URLDecode(enStr)
  dim  deStr,strSpecial
  dim  c,i,v
  deStr=""
  strSpecial="!""#$%&'()*+,/:;<=>?@[\]^`{

关键词:asp完成关键词取得(各搜索引擎,gb2312及utf-8)




Copyright © 2012-2018 盾怪网教程(http://www.dunguai.com) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版