遠(yuǎn)程抓取GOOGLE的自動(dòng)翻譯結(jié)果_.Net教程

      編輯Tag賺U幣
      教程Tag:暫無(wú)Tag,歡迎添加,賺取U幣!

      推薦:關(guān)閉按鈕點(diǎn)擊事件的捕捉
      <一>只需要在你的頁(yè)面中加入如下的腳本即可.. 以下為引用的內(nèi)容: function window.onbeforeunload() { event.returnValue = "the page

      以下為引用的內(nèi)容:
      1 Function RemoveHTML()Function RemoveHTML(strhtml)
      2 if strhtml<>"" then
      3 dim s_str as string
      4 s_str=regex.replace(strHTML,"<[^>] >","")
      5 s_str=replace(s_str,"&nbsp;","")
      6 return s_str
      7 end if
      8 End Function
      9
      10 Function china_to_english()Function china_to_english(texts,languages)
      11 Dim payload As String = "hl=zh-CN&ie=UTF8&text="& texts &"&langpair="& languages &""
      12 dim str_return as string
      13 Dim req As WebRequest = WebRequest.Create("http://translate.google.com/translate_t") ' 開(kāi)始取連接.
      14 req.Credentials = CredentialCache.DefaultCredentials '取得默認(rèn)
      15 req.Method = "POST" '以POST方式發(fā)送,這里默認(rèn)是以GET方式發(fā)送
      16 req.ContentType = "application/x-www-form-urlencoded" 'POST方式需在傳送這個(gè)編碼,如果上傳文件,則修為multipart/form-data
      17 req.timeout=10000 '連接超時(shí)定時(shí)
      18 req.ContentLength = payload.Length '頭部長(zhǎng)度
      19 Dim encoding As Encoding = Encoding.GetEncoding("UTF-8") '轉(zhuǎn)換成流,大部網(wǎng)站一般轉(zhuǎn)換成UTF-8就可以了,注意是大寫(xiě)的編碼
      20 Dim bytes As Byte() = Encoding.GetBytes(payload) '轉(zhuǎn)換成流
      21 req.ContentLength = bytes.Length '傳送流的長(zhǎng)度
      22 Dim newStream As Stream = req.GetRequestStream() '轉(zhuǎn)換寫(xiě)入
      23 newStream.Write(bytes, 0, bytes.Length) '寫(xiě)入傳送流
      24 newStream.Close() '關(guān)閉
      25 '上面發(fā)送完成,下面取得服務(wù)器返回
      26 Dim res As HttpWebResponse = CType(req.GetResponse(), HttpWebResponse) ' 傳遞返回標(biāo)識(shí)
      27 if res.StatusDescription="ok" then ' 返回取得狀態(tài).
      28 current.response.write("暫時(shí)無(wú)法連接到網(wǎng)站,請(qǐng)換用另一個(gè)程序")
      29 current.response.end()
      30 end if
      31 Dim dataStream As Stream = res.GetResponseStream() ' 返回給指針
      32 Dim reader As New StreamReader(dataStream,encoding.getencoding("gb2312")) ' 讀
      33 Dim responseFromServer As String = reader.ReadToEnd() ' 讀取所有
      34
      35 str_return=responseFromServer '賦值回傳
      36
      37 reader.Close() '接下來(lái)三個(gè)關(guān)閉
      38 dataStream.Close()
      39 res.Close()
      40
      41 dim ss as string = str_return
      42 ss = regex.replace(ss,"(?i:(. )(\<div)(. )(\>)(. )(\<\/div\>)(. ))","$5") '提取我們所要的譯文
      43 ss = RemoveHTML(ss) '刪除HTML
      44 ss = ss.substring(3) '刪除翻譯二字
      45 return ss '函數(shù)返回
      46 End function
      47
      48 在調(diào)用china_to_english(texts,languages)需要傳兩個(gè)參數(shù)第一個(gè)為要譯的文字,第二個(gè)是要進(jìn)行相對(duì)譯的語(yǔ)種代碼.


      例:中譯英,其第二個(gè)參數(shù)為:zh-Cn|en

      我導(dǎo)入的命名空間如下:

      以下為引用的內(nèi)容:

      Imports System
      Imports System.Web
      Imports System.IO
      Imports Microsoft.VisualBasic
      Imports System.Web.HttpContext
      Imports System.Web.UI
      Imports System.Web.UI.WebControls
      Imports System.Text
      Imports System.Text.RegularExpressions
      Imports System.Net

      分享:AJAX將成為移動(dòng)Web2.0時(shí)代首選開(kāi)發(fā)平臺(tái)
      一、引言 最近,Opera宣布通過(guò)他們的瀏覽器把AJAX技術(shù)應(yīng)用于移動(dòng)設(shè)備開(kāi)發(fā)中。考慮到Opera瀏覽器在目前瀏覽器市場(chǎng)(特別是在移動(dòng)瀏覽器市場(chǎng))的流行性,我們可以預(yù)計(jì)這一宣布對(duì)于整個(gè)瀏覽器市場(chǎng)

      來(lái)源:模板無(wú)憂//所屬分類:.Net教程/更新時(shí)間:2008-08-22
      相關(guān).Net教程