scraping from a website

jamal_y88

New Member
Joined
Nov 22, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
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.
page.jpg

code.jpg


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
[/CODE]
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: VBA web scraping does not owtk
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top