在线英汉字典
额,粗糙的一个工具,这只是在线用的,未连网不能使用.第二个,只能英汉使用,也就是英语单词翻译成汉语
谢谢学习一下。。 还这么多人下载? 我放一个自己弄的, 截取百度词典的,
可以英转汉,也可以汉转英,还截取注音,例句....
最重要的是, 我这个不要钱!
#include <inet.au3>
#include <array.au3>
Local $result
$result = _baidu_dict('love you')
If Not @error Then _ArrayDisplay($result)
$result = _baidu_dict('你好')
If Not @error Then _ArrayDisplay($result)
Func _baidu_dict($sString)
Local $tmp = '', $tmp1 = '', $tmp_str = ''
; 检测是否已连接上因特网
;Local Const $NETWORK_ALIVE_LAN = 0x1
;Local Const $NETWORK_ALIVE_WAN = 0x2
$tmp = DllCall("sensapi.dll", "int", "IsNetworkAlive", "str", 0x2)
If @error Then Return SetError(1)
If $tmp <> 1 Then Return SetError(2)
Local $cn_phrase ; 示例 词组
Local $pronounce = '';发音,注音
Local $bushou = '' ;汉字所属部首
Local $cn_basicmean = '' ; 中文简单释义
Local $en_simple_means ; 英文简单释义
Local $url = 'http://dict.baidu.com/s?wd='
Local $bool
If StringRegExp($sString, '[^\x00-\xff]') Then ;[\u4E00-\u9FA5]
$bool = True
$url &= _convert_chinese($sString)
Local $aResult = [['发音', ''],['英文释义', ''],['中文释义', ''],['部首', ''],['示例词组', ''],['示例句子', '']]
Else
$bool = False
$url &= $sString
Local $aResult = [['发音', ''],['中文释义', ''],['示例句子', '']]
EndIf
$data = _INetGetSource($url, False)
$data = BinaryToString($data, 4)
If $bool Then
$tmp = StringRegExp($data, '(?is)id="pronounce".+?\[(.+?)\]', 1)
If Not @error Then $pronounce = $tmp
$aResult = $pronounce
;中文的简单英文释义
$tmp = StringRegExp($data, '(?is)<div id="en\-simple\-means"(.+)</p>\h*<div', 1)
If Not @error Then
$tmp = StringRegExp($tmp, '(?i)>([^<>]+)</a>', 3)
If Not @error Then
$en_simple_means = _ArrayToString($tmp, ';')
EndIf
Else ; 网络释义
$tmp = StringRegExp($data, '(?is)id="cn\-net\-means".+?<dl>(.+?)</dl>', 1)
If Not @error Then
$tmp = StringRegExp($tmp, '(?i)<p>(.+?)</p>', 3)
If Not @error Then
$en_simple_means = _ArrayToString($tmp, ';')
EndIf
EndIf
EndIf
$aResult = $en_simple_means
;中文的中文基本释义
$tmp = StringRegExp($data, '(?i)id="cn\-basicmean".+?<p>(.+?)</p>', 1)
If Not @error Then $cn_basicmean = $tmp
$aResult = $cn_basicmean
;部首
$tmp = StringRegExp($data, '(?i)<p>部首:\h*([^<>]+)<', 1)
If Not @error Then $bushou = $tmp
$aResult = $bushou
;词组
$tmp = StringRegExp($data, '(?is)id="cn\-phrase".+?<ol>(.+?)</ol>', 1)
If Not @error Then
$tmp = StringRegExp($tmp, '(?i)<li>(.+?)</li>', 3)
If Not @error Then
For $i = 0 To UBound($tmp) - 1
$tmp1 = StringRegExp($tmp[$i], '(?i)<p>(.+?)</p>', 3)
If @error Then ContinueLoop
$tmp_str = ''
For $ii = 0 To UBound($tmp1) - 1
$tmp_str &= $tmp1[$ii] & @CRLF
Next
$cn_phrase &= $tmp_str & '**'
Next
$aResult = $cn_phrase
EndIf
EndIf
;获取例句
$aResult = _get_example_data($data)
Else
;获取发音注音
$tmp = StringRegExp($data, '(?s)xml:lang="EN\-US">([^<>]*)', 1)
If Not @error Then $pronounce = $tmp
$aResult = $pronounce
;获取英文的中文释义
$tmp = StringRegExp($data, '(?is)id="en\-simple\-means".+?<span>(.+?)</span>', 1)
If Not @error Then
$cn_basicmean = $tmp
Else ; 网络释义
$tmp = StringRegExp($data, '(?is)id="en\-net\-means".+?<dl>(.+?)</dl>', 1)
If Not @error Then
$tmp = StringRegExp($tmp, '(?i)<p>(.+?)</p>', 3)
If Not @error Then $cn_basicmean = _ArrayToString($tmp, ';')
EndIf
EndIf
$aResult = $cn_basicmean
;获取例句
$aResult = _get_example_data($data)
EndIf
Return $aResult
EndFunc ;==>_baidu_dict
Func _get_example_data($sData); 例句
Local $tmp, $tmp_str, $tmp_str2, $tmp_str3, $t, $tt
Local $example_data
$tmp = StringRegExp($sData, '\[{4}.+\]{2}', 1)
If @error Then Return $example_data
$tmp = StringRegExp($tmp, '\[?(\[{3}.+?)http:', 3)
If @error Then Return $example_data
For $i = 0 To UBound($tmp) - 1
$t = StringRegExp($tmp[$i], '(\[{2}.+?\]{2})', 3)
If @error Then ContinueLoop
$tmp_str = ''
For $ii = 0 To UBound($t) - 1
$tmp_str2 = ''
$tmp_str3 = ''
$tt = StringRegExp($t[$ii], '\["([^"]+)"', 3)
If @error Then ContinueLoop
For $iii = 0 To UBound($tt) - 1
$tmp_str3 = StringReplace($tt[$iii], '\', '')
If Not StringRegExp($tmp_str3, '\W') Then $tmp_str3 = ' ' & $tmp_str3
$tmp_str2 &= $tmp_str3
Next
$tmp_str &= $tmp_str2 & '##'
Next
$example_data &= $tmp_str & '**'
Next
Return $example_data
EndFunc ;==>_get_example_data
Func _convert_chinese($sChinese)
If $sChinese = '' Then Return SetError(1)
If StringRegExp($sChinese, '') Then Return SetError(2)
$sChinese &= '生产'
$sChinese = StringToBinary($sChinese, 4)
$sChinese = StringReplace($sChinese, '0x', '')
$sChinese = StringRegExpReplace($sChinese, '(\w{2})', '%\1')
$sChinese = StringRegExpReplace($sChinese, '(?:%\w\w){6}$', '')
Return $sChinese
EndFunc ;==>_convert_chinese
回复 3# user3000
谢谢很实用。。 回复 3# user3000
good 谢谢,学习一下,非常感谢
页:
[1]