Pausing random periods inbetween each pattern match
How might I pause for a random period of time between each pattern match? I'm running a script for each pattern match already, do I add code to that one or add an additional script to the list?
Can someone post the complete code of a script I could use?
I've seen many posts but none of them seem to work all by themselves and i'm a super-newbie.
This post seems to be most like what I"m looking for: http://community.screen-scraper.com/script_repository/BreakPoint
Code here:
------------
import java.util.Random;
// Pauses scraping session each time script is run.
// Random interval of 4 to 12 seconds
Random generator = new Random();
seconds = generator.nextInt(8) + 4;
milli = seconds * 1000;
session.log("+++Pausing for " + seconds + " seconds");
sutil.pause(milli);
-----------------
Would I Just create a script named "Pause", then add it to the scraping session as a script that runs once if pattern matches?
Jeff, If you look a little
Jeff,
If you look a little farther down the page on the sample Breakpoint script you'll notice another sample script for ramdomizing pause times.
You can either copy and paste the script into the script that you're already calling or you can have it be a standalone script.
-Scott
So, it would be a separate
So, it would be a separate script just as so, named Breakpoint, and set it to run for each match?
---------
session.breakpoint();
import java.util.Random;
// Pauses scraping session each time script is run.
// Random interval of 4 to 12 seconds
Random generator = new Random();
seconds = generator.nextInt(8) + 4;
milli = seconds * 1000;
session.log("+++Pausing for " + seconds + " seconds");
sutil.pause(milli);
------------
'The "pause" method is not
'The "pause" method is not available in this edition of screen-scraper.-- Method Invocation sutil.pause'
Is there a pause method available in the free version?
Jeff, Here's a snippet of
Jeff,
Here's a snippet of code that uses Java's sleep method.
session.log("sleeping for " + sleepTime + " milliseconds");
try {
Thread.sleep(sleepTime);
} catch(InterruptedException e) {
}
Otherwise, a kind of work around might be to create a very large HTML page whose content randomly varies in size. Have screen-scraper request this page. If it's large enough, screen-scraper will take a moment to retrieve its contents and that delay will act as a kind of pause.
-Scott
Wow, that script worked
Wow, that script worked great. It's not random but it's better than nothing. Thank you.
The html idea is too advanced for me but it sounds fascinating :)
This should make it
This should make it random.
// Pauses scraping session each time script is run.
// Random interval of 4 to 12 seconds
Random generator = new Random();
seconds = generator.nextInt(8) + 4;
sleepTime = seconds * 1000;
session.log("sleeping for " + sleepTime + " milliseconds");
try {
Thread.sleep(sleepTime);
} catch(InterruptedException e) {
}
-Scott
woah, that was perfect!
woah, that was perfect!