TA的每日心情 | 开心 2018-8-14 18:21 |
---|
签到天数: 11 天 [LV.3]偶尔看看II
状元
- 积分
- 46216
|
推荐
楼主 |
发表于 2016-11-21 23:25:48
|
只看该作者
Option Explicit
Function e2c(w As String, f As Integer) As String
On Error Resume Next
Dim html As New HTMLDocument, url
Dim i As Integer
Dim x As Variant
Dim sample() As String
With CreateObject("MSXML2.XMLHTTP")
url = "http://dict.cn/" & w
'Debug.Print url
.Open "GET", url, True
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.setRequestHeader "Referer", ""
.Send
While .readyState <> 4
DoEvents
Wend
html.body.innerHTML = .responseText
Select Case f
Case 1
e2c = Replace(html.getElementsByClassName("basic clearfix")(0).innerText, vbCrLf, "<br>")
Case 2
html.body.innerHTML = html.getElementsByClassName("phonetic")(0).innerHTML
e2c = Trim(html.getElementsByTagName("span")(0).innerText) & "<br>" & Trim(html.getElementsByTagName("span")(1).innerText)
Case 3
html.body.innerHTML = html.getElementsByClassName("layout sort")(0).innerHTML
i = 1
For Each x In html.getElementsByTagName("li")
sample = Split(x.innerText, vbCrLf, 2)
e2c = e2c & "(" & i & ")" & sample(0) & "<br>"
i = i + 1
Next
Case 4
html.body.innerHTML = html.getElementsByClassName("layout sort")(0).innerHTML
i = 1
For Each x In html.getElementsByTagName("li")
sample = Split(x.innerText, vbCrLf, 2)
e2c = e2c & "(" & i & ")" & sample(1) & "<br>"
i = i + 1
Next
Case Else
e2c = Replace(html.getElementsByClassName("basic clearfix")(0).innerText, vbCrLf, "<br>")
End Select
End With
End Function
Function vocab(w, p As Integer)
On Error Resume Next
Dim html As New HTMLDocument, url, pron, exp
url = "https://www.vocabulary.com/dictionary/definition.ajax?search=" & w
'Debug.Print url
With CreateObject("MSXML2.XMLHTTP")
.Open "get", url, True
.Send
While .readyState <> 4
DoEvents
Wend
html.body.innerHTML = .responseText
End With
Select Case p
Case 1
exp = html.getElementsByClassName("short")(0).innerText
Case 2
exp = html.getElementsByClassName("long")(0).innerText
Case Else
exp = html.getElementsByClassName("short")(0).innerText
End Select
vocab = exp
End Function
Function arr_e2c(w As String) As Variant
On Error Resume Next
Dim html As New HTMLDocument
Dim url As String
Dim i As Integer
Dim s As String
Dim x As Variant
Dim result(4) As String
Dim sample() As String
With CreateObject("MSXML2.XMLHTTP")
url = "http://dict.cn/" & w
.Open "GET", url, True
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.setRequestHeader "Referer", ""
.Send
While .readyState <> 4
DoEvents
Wend
html.body.innerHTML = .responseText
s = html.getElementsByClassName("ifufind")(0).innerText
If s <> "" Then
arr_e2c = ""
Exit Function
End If
html.body.innerHTML = html.getElementsByClassName("phonetic")(0).innerHTML
result(0) = Trim(html.getElementsByTagName("span")(0).innerText) & "<br>" & Trim(html.getElementsByTagName("span")(1).innerText)
html.body.innerHTML = .responseText
result(1) = Replace(html.getElementsByClassName("basic clearfix")(0).innerText, vbCrLf, "<br>")
html.body.innerHTML = .responseText
html.body.innerHTML = html.getElementsByClassName("layout sort")(0).innerHTML
i = 1
For Each x In html.getElementsByTagName("li")
sample = Split(x.innerText, vbCrLf, 2)
result(2) = result(2) & "(" & i & ")" & sample(0) & "<br>"
result(3) = result(3) & "(" & i & ")" & sample(1) & "<br>"
i = i + 1
Next
End With
html = Nothing
arr_e2c = result
End Function
Function arr_vocab(w As String) As Variant
On Error Resume Next
Dim html As New HTMLDocument, url, pron, exp
Dim result(2) As String
url = "https://www.vocabulary.com/dictionary/definition.ajax?search=" & w
'Debug.Print url
With CreateObject("MSXML2.XMLHTTP")
.Open "get", url, True
.Send
While .readyState <> 4
DoEvents
Wend
html.body.innerHTML = .responseText
End With
result(0) = html.getElementsByClassName("short")(0).innerText
result(1) = html.getElementsByClassName("long")(0).innerText
arr_vocab = result
End Function
好多家,呵呵
|
|