[已解决] 求一段内嵌 Google 在线翻译的代码或 exe 文件,谢谢!
本帖最后由 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 帮助也看不懂! 谢谢了!!! #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窗口时会导致卡上几秒 把你的改一下。顺便自己收藏。谢谢提问。{:face (197):}
#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
我那个帖子前辈不是看过了吗 http://www.autoitx.com/thread-10934-1-1.html
我现在还在使用,一切正常。 回复 4# afan
看我这记性,一点印象也没有。。。。谢谢!!!! 回复 3# xsjtxy
谢谢!!!! 回复 2# Ziya
谢谢!!!!!! 收下先,网页的源码看不懂,我也想编写个不用网页的.但用网页的在线翻译.不知能不能实现 http://www.autoitx.com/forum.php?mod=redirect&goto=findpost&pid=248713&ptid=19791
bob 发表于 2010-12-25 17:29 http://www.autoitx.com/images/common/back.gif
谢谢!研究学习....
页:
[1]