當前位置:成語大全網 - 新華字典 - 求助:在Excel裏面應用VBA從有道詞典獲取單詞釋義

求助:在Excel裏面應用VBA從有道詞典獲取單詞釋義

參考壹下

/view/aba98f8f84868762caaed5dd?fr=prin

or

Function worddef(str1 As String)

'/search?q=單詞&keyfrom=dict.index

Dim XH As Object

Dim s() As String

Dim str_tmp As String

Dim str_base As String

'開啟網頁

Set XH = CreateObject("Microsoft.XMLHTTP")

On Error Resume Next

XH.Open "get", "/search?q=" & str1 & "&keyfrom=dict.index", False

XH.send

On Error Resume Next

str_base = XH.responseText

XH.Close

Set XH = Nothing

str_base = Split(Split(XH.responseText, "<div id=""webTrans"" class=""trans-wrapper trans-tab"">")(0), "<span class=""keyword"">")(1)

worddef = ""

'擷取中文翻譯

str_tmp = Split((Split(str_base, "<div class=""trans-container"">")(1)), "</div>")(0)

str_tmp = Split((Split(str_tmp, "<ul>")(1)), "</ul>")(0)

s = Split(str_tmp, "<li>")

worddef = Split(s(LBound(s) + 1), "</li")(0)

For i = LBound(s) + 2 To UBound(s)

worddef= worddef & Chr(10) & Split(s(i), "</li")(0)

Next

End Function