找回密码
 加入
搜索
查看: 6683|回复: 9

[IE类操作] [已解决] 求一段内嵌 Google 在线翻译的代码或 exe 文件,谢谢!

  [复制链接]
发表于 2010-8-12 10:07:29 | 显示全部楼层 |阅读模式
本帖最后由 131738 于 2010-8-12 15:32 编辑

下面是 Google 在线翻译的网址及截图:

http://translate.google.cn/#en|zh-CN|Note%20the%20closure%20%5BX%5D%20on%20the%20title%20bar.%20%20This%20Toast%20will%20time%20out%20in%2030%20secs%20but%20clicking%20the%20%5BX%5D%20will%20resume%20the%20script%20immediately



要求内嵌截图中的红圈部分,类似金山词霸的翻译页面:



大概金山与 Google 的合作中止了,金山词霸的翻译页面已经不能使用,

而 Google 在线翻译的质量似乎比金山快译要好多了,有会 IE 的朋友请帮帮忙!

本人实在不懂 IE ,au3 的 IE 帮助也看不懂! 谢谢了!!!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-8-12 10:26:46 | 显示全部楼层
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Google翻译", 625, 375, 192, 124)
$Edit1 = GUICtrlCreateEdit("", 24, 72, 569, 273)
GUICtrlSetData(-1, "")
$Input1 = GUICtrlCreateInput("请输入待翻译的英文串", 24, 24, 481, 21)
$Button1 = GUICtrlCreateButton("翻译", 528, 24, 65, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        fanyi()
        EndSwitch
WEnd

Func fanyi()
        $key = GUICtrlRead($Input1)
        If $key = "请输入待翻译的英文串" Or $key = "" Then
                MsgBox(0, "错误", "请检查网址是否正确")
        Else
                $oIE = _IECreate("http://translate.google.cn/#en|zh-CN|"&$key,0,0)
                _IELoadWait($oIE)
                Sleep(1000)
                $oDiv = _IEGetObjById($oIE,"suggestion")
                GUICtrlSetData($Edit1,$oDiv.innertext)
                _IEQuit($oIE)
        EndIf        
EndFunc
测试后发现的问题:
1.虽然加了_IELoadWait($oIE),但有时网页貌似还是没有载入完成,导致读出的内容为0?所以加了1秒的延时
2.关闭IE窗口时会导致卡上几秒

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

发表于 2010-8-12 12:07:09 | 显示全部楼层
把你的改一下。顺便自己收藏。谢谢提问。
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

$Form1 = GUICreate("Google翻译", 625, 375, 192, 124)
$Edit1 = GUICtrlCreateEdit("Google翻译结果", 24, 72, 569, 135)
$Edit2 = GUICtrlCreateEdit("其它解释", 24, 210, 569, 135)
$Input1 = GUICtrlCreateInput("请输入待翻译的英文串", 24, 24, 481, 21)
$Button1 = GUICtrlCreateButton("翻译", 528, 24, 65, 21)
GUISetState(@SW_SHOW)



While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        fanyi()
        EndSwitch
WEnd

Func fanyi()
        $key = GUICtrlRead($Input1)
        If $key = "请输入待翻译的英文串" Or $key = "" Then
                MsgBox(0, "错误", "请检查输入是否正确")
        Else
                $oIE = _IECreate("http://translate.google.cn/#en|zh-CN|"&$key,0,0)
                Do
                $oDiv = 0
                _IELoadWait ($oIE)
                if @Error then exit
                $oDiv = _IEGetObjById($oIE,"suggestion")
                $sText = $oDiv.innertext
                Until $sText <> "0"
                GUICtrlSetData($Edit1,$sText)
                GUICtrlSetData($Edit2,"")
                $oDiv = 0
                $sText = _IEBodyReadText ($oIE)
                $sText2 = StringInStr($sText, "查看字典详细内容")
                if $sText2 <> 0 then
                $sText = StringTrimLeft($sText,$sText2+9)
                $sText = StringLeft($sText,StringInStr($sText, "更好的翻译建议")-7)
                $sText = StringReplace($sText, "词", "词:")
                GUICtrlSetData($Edit2,$sText)
                endif
                _IEQuit($oIE)
        EndIf        
EndFunc

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

发表于 2010-8-12 12:41:07 | 显示全部楼层
我那个帖子前辈不是看过了吗 http://www.autoitx.com/thread-10934-1-1.html
我现在还在使用,一切正常。
 楼主| 发表于 2010-8-12 15:31:33 | 显示全部楼层
回复 4# afan

看我这记性,一点印象也没有。。。。谢谢!!!!
 楼主| 发表于 2010-8-12 15:31:51 | 显示全部楼层
回复 3# xsjtxy

谢谢!!!!
 楼主| 发表于 2010-8-12 15:32:17 | 显示全部楼层
回复 2# Ziya

谢谢!!!!!!
发表于 2010-11-23 09:00:30 | 显示全部楼层
收下先,网页的源码看不懂,我也想编写个不用网页的.但用网页的在线翻译.不知能不能实现
发表于 2010-12-25 17:29:06 | 显示全部楼层
 楼主| 发表于 2010-12-26 01:08:42 | 显示全部楼层
bob 发表于 2010-12-25 17:29

谢谢!研究学习....
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-21 06:21 , Processed in 0.080840 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表