这是HTML代码:
<table>
<tr><td>Date:</td><td><input type='text' name='d' value=''><br>(Example: Oct. 8)</td></tr>
<tr><td>Teams:</td><td><input type='text' name='away' value=''> at <input type='text' name='home' value=''><br>(Example: Florida at Buffalo)</td></tr>
<tr><td>Time:</td><td><input type='text' name='t' value=''><br>(Example: 7:00 PM)</td></tr></table><br><input type='submit' value='Submit'>"
我正在使用此代码:
Sub extractdata()
Dim x As Long
Dim objie As Object
Set objie = CreateObject("internetexplorer.application")
objie.Top = 0
objie.Left = 0
objie.Width = 800
objie.Height = 600
objie.Visible = True
objie.navigate "http://www.dailynhlgoalies.com/loadSchedule.php"
x = 1
Dim aloha As String
Dim aloha1 As String
Dim aloha2 As String
Dim aloha3 As String
aloha = Sheet1.Range("A" & x).Value
aloha1 = Sheet1.Range("B" & x).Value
aloha2 = Sheet1.Range("C" & x).Value
aloha3 = Sheet1.Range("D" & x).Value
Application.Wait (Now + #12:00:02 AM#)
Do
DoEvents
If Err.Number <> 0 Then
objie.Quit
Set objie = Nothing
GoTo the_start:
End If
Loop Until objie.readyState = 4
objie.document.getelementbyname("d").Value = aloha
objie.document.getelementbyname("away").Value = aloha1
objie.document.getelementbyname("home").Value = aloha2
objie.document.getelementbyname("t").Value = aloha3
End Sub
但它不起作用
答案 0 :(得分:1)
您关闭了
行上的应用程序objie.Quit
Set objie = Nothing
并尝试稍后使用
objie.document.getelementbyname("d").Value = aloha
您收到错误,因为您关闭了IE并将指针设置为Nothing
此外,没有getelementbyname,只有getelementSbyname,它返回一个Collection,所以你应该写:
objie.document.getelementsbyname("d")(0).Value = aloha
答案 1 :(得分:0)
它是getElementsByName
(注意“s”)并且它返回匹配元素的集合,而不是单个元素,因此您应该执行以下操作:
objie.document.getelementsbyname("d")(0).Value = aloha
例如