从Internet Explorer获取数据

时间:2015-08-15 05:32:20

标签: excel vba excel-vba

我正在学习如何从Internet Explorer中提取源数据。我已经学会了如何从YouTube编写代码。但是,当我想修改它来测试另一个网站时,我遇到了一个错误。有人可以提出建议吗?

经过测试的网站:http://www.oxforddictionaries.com

Sub clickFormbutton()


Dim ie As Object
Dim form As Variant, button As Variant


Set ie = CreateObject("InternetExplorer.Application")


input1 = InputBox("Please enter keyword.")


With ie

.Visible = True
.navigate ("http://www.oxforddictionaries.com")


While ie.ReadyState <> 4
DoEvents
Wend


ie.document.getelementsbyname("q").Item.innertext = input1


Set form = ie.document.getElementsbytagname("form")

Set button = form(0).onsubmit


form(0).submit


Do While ie.busy: DoEvents: Loop

Set TDelements = .document.getElementsbytagname("td")
r = 0
c = 0

For Each TDelement In TDelements
Sheet1.Range("A1").Offset(r, c).Value = TDelement.innertext
r = r + 1
Next





End With

Set ie = Nothing





End Sub

0 个答案:

没有答案