Try this:
$ie = new-object -com InternetExplorer.Application $ie.Visible = $true get-content "C:\listofurl.txt" | % { $ie.navigate($_) do {sleep 1} until (-not ($ie.Busy)) Sleep 10 # pause }
- Marked as answer by Marco ShawModerator Sunday, September 18, 2011 12:59 PM
Try this:
$ie = new-object -com InternetExplorer.Application $ie.Visible = $true get-content "C:\listofurl.txt" | % { $ie.navigate($_) do {sleep 1} until (-not ($ie.Busy)) Sleep 10 # pause }
- Marked as answer by Marco ShawModerator Sunday, September 18, 2011 12:59 PM
Try this:
$ie = new-object -com InternetExplorer.Application $ie.Visible = $true get-content "C:\listofurl.txt" | % { $ie.navigate($_) do {sleep 1} until (-not ($ie.Busy)) Sleep 10 # pause }
- Marked as answer by Marco ShawModerator Sunday, September 18, 2011 12:59 PM
What if I want to infinite loop through these pages until I manually kill the process or CTRL+C?
I tried adding an
do {
...
} until ($a -eq $b)
to set some arbitrary variables which would never equal each other but that didn't work. I'd like to keep cycling through the pages in that list essentially.
EDIT:
I quickly found out how to do an infinite loop. Simply append
for (;;) { ... scriptblock }
To any scriptblock to make it loop infinitely. In my shop we used this structure to build a list of SCOM web reports and general environmental health statistics which are cycled through on a number of monitors every few minutes. Works great!
- Edited by Stephen Owen Thursday, October 13, 2011 4:52 PM Adding Content
What if I want to infinite loop through these pages until I manually kill the process or CTRL+C?
I tried adding an
do {
...
} until ($a -eq $b)
to set some arbitrary variables which would never equal each other but that didn't work. I'd like to keep cycling through the pages in that list essentially.
EDIT:
I quickly found out how to do an infinite loop. Simply append
for (;;) { ... scriptblock }
To any scriptblock to make it loop infinitely. In my shop we used this structure to build a list of SCOM web reports and general environmental health statistics which are cycled through on a number of monitors every few minutes. Works great!
- Edited by Stephen Owen Thursday, October 13, 2011 4:52 PM Adding Content
What if I want to infinite loop through these pages until I manually kill the process or CTRL+C?
I tried adding an
do {
...
} until ($a -eq $b)
to set some arbitrary variables which would never equal each other but that didn't work. I'd like to keep cycling through the pages in that list essentially.
EDIT:
I quickly found out how to do an infinite loop. Simply append
for (;;) { ... scriptblock }
To any scriptblock to make it loop infinitely. In my shop we used this structure to build a list of SCOM web reports and general environmental health statistics which are cycled through on a number of monitors every few minutes. Works great!
- Edited by Stephen Owen Thursday, October 13, 2011 4:52 PM Adding Content
I know this older, but can you post your script that uses the
for (;;)
section, I am trying to get this to work but it keeps throwing errors. I don't know where to put it.
Thanks,
Eric
Can you post your code that is throwing errors? That might be the quickest way to get you a fix.
Using the code above in a powershell console do this:
$ie | get-member
to get a list of methods and properties. You can further drill down with
$ie.document | get-member
etc, etc for all the properties.
Here's a helpful link to the IE Document Object Model:
http://msdn.microsoft.com/en-us/library/hh772384(v=vs.85).aspx
And for the wait, I've found this is more accurate for some pages:
do {sleep 1} until (!$ie.Busy -and $ie.readyState -eq 4)
I found some pages will still be doing 'something' even though IE isn't 'busy'
I should clarify that I don't know where to put the for(;;) command in the code. I used the code as listed above, it works great, but only cycles though one time.
The author stated:
I quickly found out how to do an infinite loop. Simply append
for (;;) { ... scriptblock }
I have tried appending that to the end and it doesn't work, in fact I've tried putting it several areas amongst other things in failed attempts to loop the {$ie.navigate($_) part.
I am not an expert at this stuff by any stretch, but I can copy and paste with the best of them. :-)
It would actually be a prefix, not an append:
$ie = new-object -com InternetExplorer.Application $ie.Visible = $true for (;;) { get-content "C:\listofurl.txt" | % { $ie.navigate($_) do {sleep 1} until (-not ($ie.Busy)) Sleep 10 # pause } }
That will repeat the get-content and navigate to each of the urls in the text file indefinitely.
Put this in front of your code
for (;;) {
and put this after your code
}
That is a thing of beauty! Thank you! Works great for my NOC monitor project.
I could have sworn I tried putting that there, but I guess I messed up the exact placement.
set-ExecutionPolicy Unrestricted $ie = new-object -com InternetExplorer.Application $ie.Visible = $true $ie.FullScreen = $true for (;;) { get-content "C:\NOC\urls.txt" | % { $ie.navigate($_) do {sleep 1} until (!$ie.Busy -and $ie.readyState -eq 4) Sleep 45 # pause } }
I believe my question belongs in this thread, as I'm inquiring specifically about the code in this thread and the fact that the code presented above only works in the most basic circumstances and doesn't handle some URLs. For example, if you put http://www.securitywizardry.com/radar.htm
as one of the URLs in your list, you'll find that the script halts on that page and will not progress to the next URL. This occurs even when scrapping the IE state interrogation:
do {sleep 1} until (!$ie.Busy -and $ie.readyState -eq 4)
and going with only a sleep timer.
Anyone have ideas for how to make this work for most types of dynamic web pages?
I believe my question belongs in this thread, as I'm inquiring specifically about the code in this thread and the fact that the code presented above only works in the most basic circumstances and doesn't handle some URLs.
You should always start your own thread. You can link back to this thread if you wish, but adding a post to an already answered thread is not a good way to have anyone new see this.
The best method is to start a new thread, post your code, your errors, and everything you've tried so far.