Get HTML from a site using the DOM

I am trying to write a script in powershell that I can use to get HTML code from a website after executing a request.

On my own machine, I can run the following, which works without problems, but when I try to run it on a Server 2008 machine, I do not get the output from the Document.Body.InnerHTML command, all the details of Document.GetElementById work without problems.

$ie = New-Object -com InternetExplorer.Application $ie.silent = $true $ie.navigate2("http://www.mxtoolbox.com/") while($ie.busy) {start-sleep 1} $ie.Document.getElementById("ctl00_ContentPlaceHolder1_txtToolInput").Value = "mx:domain.co.uk" $ie.Document.getElementById("ctl00_ContentPlaceHolder1_btnAction").Click() Start-Sleep -Seconds 10 $ie.Document.body.innerHTML | Out-File "C:\NETESP\MXRecords\MXRecordsHTML.txt" -Encoding ASCII $ie.Quit() 

Is there something I need to install on server 2008 to return this value?

Thanks at Advance

+4
source share
1 answer

Could there be a problem with synchronization? I can not test in 2008, but I will try:

 $ie = New-Object -com InternetExplorer.Application $ie.silent = $false $ie.navigate2("http://www.mxtoolbox.com/") while($ie.busy) {start-sleep 1} $ie.Document.getElementById("ctl00_ContentPlaceHolder1_txtToolInput").Value = "mx:domain.co.uk" $ie.Document.getElementById("ctl00_ContentPlaceHolder1_btnAction").Click() # wait for the result page While($ie.LocationURL -eq 'http://www.mxtoolbox.com/') { Write-Warning "Waiting for result" Start-sleep 1 } # grab the table html $table = $ie.Document.getElementsByTagName('TABLE') | Where-Object {$_.className -eq 'table table-striped table-bordered table-condensed tool-result-table'} $table.outerHTML | Out-File "C:\NETESP\MXRecords\MXRecordsHTML.txt" -Encoding ASCII $ie.Quit() 
+3
source

Source: https://habr.com/ru/post/1434558/


All Articles