|
楼主 |
发表于 2020-2-13 20:59
|
显示全部楼层
接上,继续。。。。。。
Public Function GetFrBY(tmpWord As String, Nuber As Integer)
'必应,用时2分25秒,较慢。
'http://cn.bing.com/dict/search?q=about+to&go=%E6%8F%90%E4%BA%A4&qs=bs&form=CM
'http://cn.bing.com/dict/search?q=about+to&go=提交&qs=bs&form=CM
Dim XH As Object
Dim s() As String
Dim str_tmp As String, url
Dim str_base As String
If Len(tmpWord) = 0 Then Exit Function
tmpTrans = "": tmpPhonetic = ""
tmpWord = Replace(tmpWord, " ", "+")
'URL = "http://cn.bing.com/dict/search?q=" & tmpWord & "&go=%E6%8F%90%E4%BA%A4&qs=bs&form=CM"
url = "http://cn.bing.com/dict/search?q=" & tmpWord
Set XH = CreateObject("Msxml2.XMLHTTP") 'Microsoft.XMLHTTP")
On Error Resume Next
XH.Open "GET", url, 0 'True
XH.send '(Null)
While XH.readyState <> 4
DoEvents
Wend
str_base = XH.responseText
' XH.Close
Set XH = Nothing
'取得音标部分
yb = Split(Split(str_base, "<div class=""hd_prUS"">")(1), "<span class=""pos"">")(0)
'取得中文含义部分
hy = Split(str_base, "<div class=""hd_div1"">")(0)
'对音标部分进行分解,分别取得英国和美国音标
yb = Split(yb, "<div class=""hd_pr"">")
ybUS = Split(Split(str_base, "美[")(1), ",")(0)
ybEN = Split(Split(str_base, "英[")(1), ",")(0)
tmpPhonetic = "美 [" & ybUS & " 英 [" & ybEN
'对中文含义分解
hy = Split(hy, "<span class=""pos"">")
hytmp = ""
For i = LBound(hy) + 1 To UBound(hy)
hytmp = hytmp & DelHtml(Split(hy(i), "</span></span>")(0)) & vbCrLf
Next i
If UBound(hy) = 0 Then hytmp = ""
tmpTrans = Left(hytmp, Len(hytmp) - 1) '
' tmpTrans = Replace(Split(Split(str_base, "],")(2), " 网络释义:")(0), "; ", Chr(10))
Select Case Nuber
Case 1: GetFrBY = tmpTrans '获取中文词
Case 2: GetFrBY = tmpPhonetic '获取英文的音标
Case 3: GetFrBY = tmpTrans & vbCr & tmpPhonetic
End Select
End Function
Public Function 必应抓汉词(isr, Nub)
'isr 为英文单词,相当于专业情况下英译汉词典,
'为英语老师制作英译汉单词表省心,只可惜其抓音标的能力名存实亡。
'盼望网络高人完善之。
Dim html As New HTMLDocument, i, url
On Error Resume Next
With CreateObject("Microsoft.XMLHTTP")
url = "http://cn.bing.com/dict/search?q=" & isr
.Open "get", url, True
.send
If .Status = 200 Then
While .readyState <> 4
DoEvents
Wend
html.body.innerHTML = .responseText
If Nub = 1 Then
必应抓汉词 = html.getElementsByClassName("hd_p1_1")(0).innerText '抓音表
ElseIf Nub = 2 Then
必应抓汉词 = html.getElementsByTagName("ul")(1).innerText '抓中文翻译
End If
Else
必应抓汉词 = "无网络"
End If
End With
End Function
Function GetURL$(txt$)
'备用函数1
'作为英汉词通函数的子函数
'Dim a() As Byte
'a = StrConv(txt, vbFromUnicode, &H804)
For i = 1 To Len(txt)
txt1 = Mid(txt, i, 1)
If Abs(Asc(txt1)) < 128 Then
GetURL = GetURL & txt1
Else
GetURL1 = Application.Hex2Bin(Left(Hex(AscW(txt1)), 2), 8)
GetURL1 = GetURL1 & Application.Hex2Bin(Right(Hex(AscW(txt1)), 2), 8)
GetURL1 = Application.Replace(Application.Replace(GetURL1, 11, , 10), 5, , 10)
GetURL2 = "%E" & Application.Bin2Hex(Left(GetURL1, 4))
GetURL2 = GetURL2 & "%" & Application.Bin2Hex(Mid$(GetURL1, 5, 8))
GetURL2 = GetURL2 & "%" & Application.Bin2Hex(Mid$(GetURL1, 13, 8))
GetURL = GetURL & GetURL2
End If
Next
'如果一律转码是: GetURL = GetURL & "%" & Right("0" & Hex(a(i)), 2)
End Function
Function DelHtml(strh) '正则提取字符串
'备用函数2
'作为字母函数名的诸多函数的子函数
Dim A As String
Dim RegEx As Object
'Dim mMatch As Match
'Dim Matches As matchcollectio
A = strh
A = Replace(A, Chr(13) & Chr(10), "")
' A = Replace(A, Chr(32), "")
A = Replace(A, Chr(9), "")
A = Replace(A, "</p>", vbCrLf) '给段落后加上回车
Set RegEx = CreateObject("vbscript.regexp") '引入正则表达式
With RegEx
.Global = True
.Pattern = "\<[^<>]*?\>" '用<>括起来的html符号
.MultiLine = True '多行有效
.ignorecase = True '忽略大小写(网页处理时这个参数比较重要)
A = .Replace(A, "") '将html符号全部替换为空
End With
A = Trim(A)
'特殊符号处理
A = Replace(A, "<", "<")
A = Replace(A, ">", ">")
A = Replace(A, "&", "&")
A = Replace(A, """, "\")
A = Replace(A, "&-->", vbCrLf)
A = Replace(A, "æ", ChrW(230)) 'æ
A = Replace(A, " ", ChrW(160)) ' 
A = Replace(A, " ", " ") ' ?
DelHtml = A
End Function |
|