locked
How to count table rows RRS feed

  • Question

  • Hi Experts,

    How to count table rows.

    Thanks and Best Regards

    Thursday, September 20, 2018 9:21 AM

All replies

  • Count?  Table?

    Try "1,2,3,4…"


    \_(ツ)_/

    Thursday, September 20, 2018 9:28 AM
  • Simple example:

    Get-Process | measure | select count

    Thursday, September 20, 2018 9:36 AM
  • Hi jrv,

    Thanks for the reply. I am new on using powershell

    Below is my sample code..

    How can i use your code.

    $clsid = New-Object Guid 'D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E'
    $type = [Type]::GetTypeFromCLSID($clsid)
    $ie = [Activator]::CreateInstance($type)
    
    $ie.visible=$true
    
    $ie.navigate('http:url.com')
    while($IE.Busy) {
      Start-Sleep -Milliseconds 100
    }
    $table=$ie.document.getelementbyID('ctl00_ContentPlaceHolder1_GridView2')


     Thanks and Best Regards.


    • Edited by kai012 Thursday, September 20, 2018 9:41 AM
    Thursday, September 20, 2018 9:41 AM
  • You would have to get the total number of TR tags in the table if it is a "table".  Many sites do not use a table but just generate a set of "pre" tagged elements.

    There is no way to answer your question without access to the site.

    The way to create an IE instance is:

    $ie = New-Object -ComObject InternetExplorer.Application.

    This does in one step what it takes you three to do.


    \_(ツ)_/

    Thursday, September 20, 2018 9:47 AM
  • You can also get the "table" COM object and get the "Rows" count.

    $table.Rows.Length


    \_(ツ)_/


    • Edited by jrv Thursday, September 20, 2018 10:13 AM
    Thursday, September 20, 2018 9:49 AM
  • Sorry.  I forgot. For parsed HTML the method is.

    $table.Rows.Length

    Rows can be addressed as

    $table.Rows[0]
    $table.Rows[0].Cells[1].innerText


    \_(ツ)_/



    Thursday, September 20, 2018 10:13 AM