Asked by:
How to code this PowerShell?

Question
-
Referring to following coding, I would like to know on why not able to save html into text file.
$ieObject = New-Object -ComObject 'InternetExplorer.Application'
$ieObject
$ieObject.Visible = $true
$ieObject.Navigate("http://www.hkexnews.hk/index_c.htm")
# $Doc.body.innerHTML$Doc.body.innerHTML | Out-File "C:\Temp\HTML.txt"
$ieObject.Quit()Does anyone have any suggestions?
Thanks in advance for any suggestions
Thanks in advance for any suggestions
- Moved by Bill_Stewart Friday, March 9, 2018 7:32 PM Help vampire
Friday, September 29, 2017 7:08 AM
All replies
-
$ieObject.Document.Body.innerHTML|Out-File C:\Temp\HTML.txt
\_(ツ)_/
Friday, September 29, 2017 7:18 AM -
I have tried following both statements, but HTML.txt file is still blank.
$ieObject.Document.Body.innerHTML|Out-File C:\Temp\HTML.txt
$ieObject.Document.Body.innerHTML | Out-File C:\Temp\HTML.txt
Do you have any suggestions on what wrong it is? would it be IE setting issue? How to check?
Thank you very much for any suggestions (^v^)
Thanks in advance for any suggestions
Friday, September 29, 2017 7:46 AM -
Works fine for me.
\_(ツ)_/
Friday, September 29, 2017 7:52 AM -
When I run each code within PowerShell one at a time, it works and able to save into text file, but when I run the script containing all following codes, it does not able to save into text file.
Somehow, I need to hold the process with script and make sure each line of codes finished before running the next line.
Do you have any suggestions on how to hold the process within PowerShell Script?
Thank you very much for any suggestions (^v^)$ieObject = New-Object -ComObject 'InternetExplorer.Application'
$ieObject
$ieObject.Visible = $true
$ieObject.Navigate("http://www.hkexnews.hk/index_c.htm")
$ieObject.Document.Body.innerHTML | Out-File C:\Temp\HTML.txt
$ieObject.Quit()
Thanks in advance for any suggestions
- Edited by oemMicrosoft Saturday, September 30, 2017 4:59 PM
Saturday, September 30, 2017 1:25 PM -
For the last time, this is the correct line of code to save to a file.
$ieObject.Document.Body.innerHTML | Out-File C:\Temp\HTML.txt
\_(ツ)_/
- Proposed as answer by jrv Saturday, September 30, 2017 3:47 PM
Saturday, September 30, 2017 3:47 PM -
Coding is updated.
Question :
When I run each code within PowerShell one at a time, it works and able to save into text file, but when I run the script containing all following codes, it does not able to save into text file.
Somehow, I need to hold the process with script and make sure each line of codes finished before running the next line.
Do you have any suggestions on how to hold the process within PowerShell Script?
Thank you very much for any suggestions (^v^)Thanks in advance for any suggestions
Saturday, September 30, 2017 5:00 PM -
PowerShell runs one line at a time until it is finished before running the next line.
\_(ツ)_/
Saturday, September 30, 2017 7:46 PM -
That is not true under my situation.
When I run each code within PowerShell manually one at a time, it works and able to save into text file, but when I run the script, it does not able to save into text file.
Do you have any suggestions on why script cannot save into text file?
Thank you very much for any suggestions (^v^)
Thanks in advance for any suggestions
Saturday, September 30, 2017 9:47 PM -
Start here: https://mva.microsoft.com/en-us/training-courses/getting-started-with-microsoft-powershell-8276
After navigate add "sleep 30".
<o:p></o:p>
\_(ツ)_/
- Proposed as answer by Richard MuellerMVP, Banned Tuesday, October 10, 2017 7:18 PM
Saturday, September 30, 2017 9:50 PM -
You can also do this:
Invoke-WebRequest http://www.hkexnews.hk/index_c.htm -OutFile C:\Temp\HTML.txt
\_(ツ)_/
- Edited by jrv Saturday, September 30, 2017 9:54 PM
Saturday, September 30, 2017 9:54 PM -
Thank you very much for suggestions (^v^)
Thanks in advance for any suggestions
Sunday, October 1, 2017 1:24 PM