サイトからデータを自動取得
|A列|B列|C列|D列|E列|F列|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|h4要素|1番目のtd要素|2番目のtd要素|3番目のtd要素|4番目のtd要素|更新日|
Sub GetDataList()
'オブジェクト変数にIEへの参照を格納する
Dim ieApp As InternetExplorer
Set ieApp = New InternetExplorer
ieApp.Visible = True 'IEのウィンドウを表示
'ページを繊維完了するまで待つ
ieApp.navigate "https://excel23.com/vbaweb/"
Do While ieApp.Busy = True Or ieApp.readyState < READYSTATE_COMPLETE
DoEvents
Loop
'HTMLDocumentオブジェクトを取得
Dim doc As HTMLDocument
Set doc = ieApp.document
'listクラスの要素の個数を取得
Dim listLen As Long
listLen = doc.getElementsByClassName("list").Length
'listクラスを0番目から順に変数に取得
Dim i As Long
For i = 0 To listLen - 1
Dim el As IHTMLElement
Set el = doc.getElementsByClassName("list")(i)
'h4要素のテキストを取得
Cells(i + 2, 1).Value = el.getElementsByTagName("h4")(0).innerText
'td要素のテキストを取得
Cells(i + 2, 2).Value = el.getElementsByTagName("td")(0).innerText
Cells(i + 2, 3).Value = el.getElementsByTagName("td")(1).innerText
Cells(i + 2, 4).Value = el.getElementsByTagName("td")(2).innerText
Cells(i + 2, 5).Value = el.getElementsByTagName("td")(3).innerText
'更新日のテキストを取得
Dim str As String
str = el.getElementsByClassName("date")(0).innerText
str = Right(str, Len(str) - 4)
Cells(i + 2, 6).Value = str
Next i
Set doc = Nothing
ieApp.Quit
Set ieApp = Nothing
End Sub