Hi,
I am trying to extract the table from this page " View Contents" . I tried with classname and tagname but it only extracted from the page "View all Events" and only the header from "View Contents"
Does anyone have an idea how to extract it or at least how to extract only one column or how get the number of the rows in this table.
thanks in advance.
here is the code and the html page.
[/CODE]
I am trying to extract the table from this page " View Contents" . I tried with classname and tagname but it only extracted from the page "View all Events" and only the header from "View Contents"
Does anyone have an idea how to extract it or at least how to extract only one column or how get the number of the rows in this table.
thanks in advance.
here is the code and the html page.
VBA Code:
[CODE=vba]Sub WebScrapeTable()
Dim IEObject As InternetExplorer
Set IEObject = New InternetExplorer
IEObject.Visible = True
IEObject.Navigate Url:="Website"
While IEObject.Busy
DoEvents
Wend
Debug.Print IEObject.LocationURL
Dim IEDocument As HTMLDocument
Set IEDocument = IEObject.Document
Dim IETables As IHTMLElementCollection
Dim IETable As IHTMLTable
Dim IERow As IHTMLTableRow
Dim IECell As IHTMLTableCell
Dim RowCount As Integer
Dim max_rows As Integer
Dim max_cols As Integer
Dim ColCount As Integer
Dim i As Integer
Dim j As Integer
RowCount = 1
Set IETable = IEDocument.getElementsByTagName("table")(2)
max_rows = IETable.Rows.Length
For Each IERow In IETable.Rows
If RowCount = 1 Then
max_cols = IERow.Cells.Length
End If
ColCount = 1
For Each IECell In IERow.Cells
Debug.Print "----------"
Debug.Print IECell.innerText
If IECell.colSpan > 1 Then
For i = 1 To Application.WorksheetFunction.Min(IECell.colSpan, max_cols)
If IECell.rowSpan > 1 Then
For j = RowCount To RowCount + IECell.rowSpan - 1
If j <= max_rows Then
ThisWorkbook.Worksheets("Tabelle2").Cells(j, ColCount).Value = IECell.innerText
End If
Next
Else
If ThisWorkbook.Worksheets("Tabelle2").Cells(RowCount, ColCount).Value = "" Then
ThisWorkbook.Worksheets("Tabelle2").Cells(RowCount, ColCount).Value = IECell.innerText
End If
End If
ColCount = ColCount + 1
Next
Else
If IECell.rowSpan > 1 Then
For i = RowCount To RowCount + IECell.rowSpan - 1
If i <= max_rows Then
If ThisWorkbook.Worksheets("Tabelle2").Cells(i, ColCount).Value = "" Then
ThisWorkbook.Worksheets("Tabelle2").Cells(i, ColCount).Value = IECell.innerText
Else
ThisWorkbook.Worksheets("Tabelle2").Cells(i, ColCount + 1).Value = IECell.innerText
End If
End If
Next
Else
If ThisWorkbook.Worksheets("Tabelle2").Cells(RowCount, ColCount).Value = "" Then
ThisWorkbook.Worksheets("Tabelle2").Cells(RowCount, ColCount).Value = IECell.innerText
Else
ThisWorkbook.Worksheets("Tabelle2").Cells(RowCount, ColCount + 1).Value = IECell.innerText
End If
End If
ColCount = ColCount + 1
End If
Next
RowCount = RowCount + 1
Next
End Sub