|
こんにちは。
とりあえず、サンプルとして。1ページ目のみの取得です。
Sub getWebData2()
Const myURL = "http://finance.nifty.com/stocks/servlet/stocks034"
Dim myIE As New InternetExplorer
Dim myObj As Object
Dim i As Long, j As Long
Dim myTitle As Variant
myTitle = Array("コード", "銘柄名", "市場", "業種", "現在値", "前日比", "総合診断")
myIE.Visible = True
myIE.navigate myURL
Do While myIE.Busy = True
DoEvents
Loop
On Error GoTo trap
myIE.document.form1("type").Value = "0050"
On Error GoTo 0
myIE.document.form1.submit
Do While myIE.Busy = True
DoEvents
Loop
i = 1
Cells.Delete
Range("a1").Resize(, 7).Value = myTitle
For Each myObj In myIE.document.all("formpl").all
If myObj.tagName = "TR" Then
i = i + 1
j = 1
End If
If myObj.tagName = "TD" Then
If j <= 7 Then Cells(i, j).Value = myObj.innerText
j = j + 1
End If
Next
Exit Sub
trap:
MsgBox "NG"
End Sub
結構不安定なので、たまに失敗("NG")します。
では。
|
|