871224 发表于 2009-11-12 23:27:01

如何实现在GUI上输入内容拿到IE里面的返回结果

请问路过的大侠,如何在GUI里面输入一个内容,拿到IE页面(一定是可以打开的IE页面,函数不算)的返回结果,如翻译单词

会的教下,先谢谢了

871224 发表于 2009-11-13 08:53:58

哪位大侠 教下呀:face (18):

871224 发表于 2009-11-14 14:27:26

哪位大侠教下:face (13):

871224 发表于 2009-11-15 14:05:07

:face (13):

afan 发表于 2009-11-15 21:55:20

本帖最后由 afan 于 2009-11-17 15:32 编辑

#include <EditConstants.au3>
#include <WindowsConstants.au3>

GUICreate("在线英译汉", 400, 300)
$Edit1 = GUICtrlCreateEdit("请在此输入英文", 5, 5, 390, 130, $WS_VSCROLL + $ES_WANTRETURN)
$Bt1 = GUICtrlCreateButton("", 5, 142, 225, 22)
GUICtrlSetData($Bt1, '在线翻译以上英文')
$Bt2 = GUICtrlCreateButton('清空', 230, 142, 80, 22)
$Bt3 = GUICtrlCreateButton('退出', 310, 142, 86, 22)
$Edit2 = GUICtrlCreateEdit("", 5, 170, 390, 105, $WS_VSCROLL + $ES_WANTRETURN)
GUICtrlCreateLabel('Afan - www.autoitx.com', 120, 280, 180, 17)
GUICtrlSetState(-1, 144)
GUISetState()

While 1
        Switch GUIGetMsg()
                Case - 3, $Bt3
                        Exit
                Case $Bt1
                        $a = StringRegExpReplace(GUICtrlRead($Edit1), @CR, '%0D%0A')
                        If $a <> '' Then
                                GUICtrlSetData($Bt1, '正在提交翻译,请稍候...')
                                GUICtrlSetState($Bt1, 144)
                                $sR = StringRegExp(Post($a), 'suggestion>([^<]+)</textarea>', 3)
                                If @error = 0 Then
                                        $a = StringRegExpReplace($sR, '&lt;br&gt;&lt;br&gt;', @CRLF)
                                        GUICtrlSetData($Edit2, $a)
                                Else
                                        MsgBox(48, '出错', '网站貌似改版,读取出错,请联系本人')
                                EndIf
                                GUICtrlSetData($Bt1, '在线翻译以上英文')
                                GUICtrlSetState($Bt1, 80)
                        Else
                                MsgBox(48, '注意', '请在上输入框输入英文 ')
                        EndIf
                Case $Bt2
                        GUICtrlSetData($Edit2, '')
                        GUICtrlSetData($Edit1, '')
        EndSwitch
WEnd

Func Post($Word)
        $oHTTP = ObjCreate("Microsoft.xmlhttp")
        $oHTTP.Open("Post", "http://translate.google.com/translate_t", False)
        $oHTTP.Send("text=" & $Word & "&langpair=en%7Czh-CN&hl=zh-CN&newwindow=1&ie=UTF-8&oe=UTF-8")
        $sReturn = BinaryToString($oHTTP.responseBody, 4)
        Return $sReturn
EndFunc   ;==>Post貌似翻译网站改版了,修改了下 http://www.autoitx.com/forum.php?mod=viewthread&tid=10934

ebhb 发表于 2009-11-15 22:22:44

不错,收藏了。
页: [1]
查看完整版本: 如何实现在GUI上输入内容拿到IE里面的返回结果