乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      asp實(shí)現(xiàn)關(guān)鍵詞獲取(各搜索引擎,gb2312及utf-8)

       duduwolf 2005-09-24

      不知道為什么現(xiàn)在各大搜索引擎編碼居然不一樣.當(dāng)然不是gb2312就是utf-8了.編碼問題是比較頭疼的問題...頭疼的不要命...

      我們獲得關(guān)鍵詞,一般是通過來訪頁面的url進(jìn)行分析的.比如

      http://www.google.com/search?hl=zh-CN&q=%E5%AD%A4%E7%8B%AC&lr=

      各位肯定知道這個(gè)是通過urlencode編碼的.

      我們得到其中的信息,需要進(jìn)行2步.第一步是進(jìn)行urldecode,在我們普通參數(shù)活得的時(shí)候,這個(gè)是由asp自己來進(jìn)行的,但是現(xiàn)在我們不得不進(jìn)行手工解碼.

      網(wǎng)上函數(shù)很多,但都是針對于gb2312頁面解gb2312.utf-8的.對于這個(gè),我們可以很輕松的先進(jìn)行解碼,然后根據(jù)搜索引擎判斷它的編碼,如果是utf-8就再轉(zhuǎn)換為gb2312.

      但是由于我的網(wǎng)站是utf-8頁面的.而utf-8頁面我找到的只有解utf-8字符的urldecode編碼的.在這里停頓了很久,最后我只能用最糟糕的方法,把拆分出來的關(guān)鍵詞用xmlhttp提交到一個(gè)gb2312的asp頁面,然后活得亂碼(gb2312)后再進(jìn)行g(shù)b2312 to utf-8的轉(zhuǎn)換.

      下面主要實(shí)現(xiàn)代碼.

      Public Function GetSearchKeyword(RefererUrl) ‘搜索關(guān)鍵詞
       if RefererUrl="" or len(RefererUrl)<1 then exit function
         
        on error resume next
       
        Dim re
        Set re = New RegExp
        re.IgnoreCase = True
        re.Global = True
        Dim a,b,j
        ‘模糊查找關(guān)鍵詞,此方法速度較快,范圍也較大
        re.Pattern = "(word=([^&]*)|q=([^&]*)|p=([^&]*)|query=([^&]*)|name=([^&]*)|_searchkey=([^&]*)|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)
        ‘輸入一堆有%分隔的字符串,先分成數(shù)組,根據(jù)utf8規(guī)則來判斷補(bǔ)齊規(guī)則
        ‘輸入:關(guān) E5 85 B3  鍵  E9 94 AE 字   E5 AD 97
        ‘輸出:關(guān) 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))
            ‘判斷第一次出現(xiàn)0的位置,
            ‘可能是1(單字節(jié)),3(3-1字節(jié)),4,5,6,7不可能是2和大于7
            ‘理論上到7,實(shí)際不會(huì)超過3。
            WeiS=instr(v,"0")
            v=right(v,len(v)-WeiS)‘第一個(gè)去掉最左邊的WeiS個(gè)
            i=i+3
            for i2=2 to WeiS-1
              c=c16to2(Mid(enStr,i+1,2))
              c=right(c,len(c)-2)‘其余去掉最左邊的兩個(gè)
              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)
       ‘這個(gè)函數(shù)是用來轉(zhuǎn)換16進(jìn)制到2進(jìn)制的,可以是任何長度的,一般轉(zhuǎn)換UTF-8的時(shí)候是兩個(gè)長度,比如A9
       ‘比如:輸入“C2”,轉(zhuǎn)化成“11000010”,其中1100是"c"是10進(jìn)制的12(1100),那么2(10)不足4位要補(bǔ)齊成(0010)。
       dim tempstr
       dim i:i=0‘臨時(shí)的指針

       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位那么補(bǔ)齊4位數(shù)
        loop
        c16to2=c16to2 & tempstr
       next
      end function

      function c2to16(x)
        ‘2進(jìn)制到16進(jìn)制的轉(zhuǎn)換,每4個(gè)0或1轉(zhuǎn)換成一個(gè)16進(jìn)制字母,輸入長度當(dāng)然不可能不是4的倍數(shù)了

        dim i:i=1‘臨時(shí)的指針
        for i=1 to len(x)  step 4
         c2to16=c2to16 & hex(c2to10(mid(x,i,4)))
        next
      end function

      function c2to10(x)
        ‘單純的2進(jìn)制到10進(jìn)制的轉(zhuǎn)換,不考慮轉(zhuǎn)16進(jìn)制所需要的4位前零補(bǔ)齊。
        ‘因?yàn)檫@個(gè)函數(shù)很有用!以后也會(huì)用到,做過通訊和硬件的人應(yīng)該知道。
        ‘這里用字符串代表二進(jìn)制
         c2to10=0
         if x="0" then exit function‘如果是0的話直接得0就完事
         dim i:i=0‘臨時(shí)的指針
         for i= 0 to len(x) -1‘否則利用8421碼計(jì)算,這個(gè)從我最開始學(xué)計(jì)算機(jī)的時(shí)候就會(huì),好懷念當(dāng)初教我們的謝道建老先生??!
          if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i)
         next
      end function

      function c10to2(x)
      ‘10進(jìn)制到2進(jìn)制的轉(zhuǎn)換
        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="!""#$%&‘()*+,/:;<=>?@[\]^`{ |}~%"
        for  i=1  to  len(enStr)
          c=Mid(enStr,i,1)
          if  c="%"  then
          v=eval("&h"+Mid(enStr,i+1,2))
          if  inStr(strSpecial,chr(v))>0  then
          deStr=deStr&chr(v)
          i=i+2
          else
          v=eval("&h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2))
          deStr=deStr&chr(v)
          i=i+5
          end  if
          else
          if  c="+"  then
          deStr=deStr&" "
          else
          deStr=deStr&c
          end  if
          end  if
        next
        URLDecode=deStr
      end function

      許多代碼都是網(wǎng)上的.找不到作者.

      PS:現(xiàn)在暑假就要接受,由于家庭原因我不想留在我的城市.中考到達(dá)本地重點(diǎn).不想說城市名字.否則會(huì)招來熟人.只要不在山東的學(xué)校算是重點(diǎn)的能不能聯(lián)系下.

      QQ:32113739

      對程序有極大興趣,但信息奧賽只活得一等的X名.因?yàn)槲艺J(rèn)為技術(shù)不應(yīng)該在所謂競賽中體現(xiàn),就如才能不應(yīng)該在那些無意義的考試中體現(xiàn)一樣.電子作品也弄了各省一等..不過也一般.學(xué)習(xí)一般...所以只要是一般重點(diǎn)就好了..只是不想在離家太近的地方.

      現(xiàn)在asp十分熟練,雖然有些知識缺陷,比如編碼問題(汗...),但是網(wǎng)絡(luò)如此大,我想我不是只有在課本中才能得到所謂的知識.而且現(xiàn)在正在啃asp.net的書,如果貴校做網(wǎng)站完全可以幫忙.

      對新技術(shù)十分狂熱,雖然被他們稱為審美有障礙的人.但我想看到結(jié)構(gòu)偶的程序還不至于吐血.

      算了..再貼點(diǎn).

      偶開發(fā)D Database+asp ->xml+xslt->xhtml +css 的算是叫CMS的東西

      http://www.

      也用了CSDN用的FCK編輯器,今天上來才發(fā)現(xiàn)換了.不過那個(gè)FCK的FIle系統(tǒng)讓偶統(tǒng)統(tǒng)改掉.

      這個(gè)系統(tǒng)在暑假結(jié)束前一定會(huì)發(fā)布.不過很多朋友說易用性有問題...很多人不會(huì)xslt.汗...

      唉...如果找不到學(xué)校.我也許會(huì)漂泊,也許會(huì)消失吧.當(dāng)然這不是威脅..只是恨我的城市,恨那里看到的,干過的一切.

        本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多