Home > Back-end >  Outlook displays "mshtml.HTMLTableRowClass" instead of Html Row
Outlook displays "mshtml.HTMLTableRowClass" instead of Html Row

Time:06-28

I'm trying to get a row of a table from a Webpage and fill the HTML Code into an HTML E-Mail. I'm using Powershell for this.

$ie = New-Object -com InternetExplorer.Application
$ie.visible = $false
$ie.navigate(www.example.com) 

$htmlDetailedRow = $ie.document.documentElement.getElementsByClassName("className")

Above you see how I get the element that I want to display in my E-Mail.

$body = @"
<html>
<body>
    <div >
        <table>
            $htmlDetailedRow
       </table>
    </div>
</body>
</html>
"@

Above you see my HTML for the Email.

 <tr >
  <td colspan="5" style="border-top: 0; border-bottom: 0; padding: 0">
    <table  style="margin: 5px 0 0 0; width: 100%">
      <tbody>
        <tr>
          <td style="text-align: left; width: 25%"><i>Date</i></td>
        </tr>
        <tr>
          <td style="text-align: left; width: 25%">22.03.2022</td>
          <td style="text-align: left; width: 30%">Text</td>
          <td style="text-align: left; width: 15%">1</td>
          <td style="text-align: left; width: 15%">5.136</td>
        </tr>
      </tbody>
    </table>
  </td>
</tr>

Above you can see the row I want to grab from the Webpage. My idea is to take the row and insert into a table in my Email HTML. The Webpage is behind a Login so unfortunately I can't link to the Page.

The HTML is working fine but the $htmlDetailedRow wont display right. Instead it displays "mshtml.HTMLTableRowClass". I know I have to convert $htmlDetailedRow somehow, but I have no idea how.

I hope someone can help me. Thanks.

CodePudding user response:

It would help to see what the object $htmlDetailedRow looks like.

$htmlDetailedRow | get-member | clip

Then you can just paste into a new code block when editing your question.


It looks like you're trying to download the content of a webpage and parse it for a table. I created a function that does that, you can grab it from here. Check out the examples.


This is a bit off-topic, but it's best to stay away from internet explorer, or any app or tech that is end of life. No matter how benign your use case, it creates more work for you in the future and is less secure. In this case, like, REALLY less secure!

Invoke-WebRequest (Alias iwr) is the PowerShell way to get data from a web resource.

CodePudding user response:

I figured it out. Because I was using getElementsByClassName("className"), it returned a array back. So to get to the innerHtml i had to acess like this.

$htmlDetailedRow = $ie.document.documentElement.getElementsByClassName("className")
    
$htmlDetailedRow[0].innerHTML
  • Related