Check for existance of script
I'm changing the way my global scripts work and I'm wondering if there's a way to know if a script exists.
I have a global script that all scrapes run when starting. I want it to look for a script with the name of the scrape with ".required" appended to it. So "general.info" scrape would have a script called "general.info.required". I would like the existance of the script to be optional. Some scrapes are simple, others need preprocessing.
So: How do I most efficiently check if a script exists? try/catch a session.executeScript, or is there a way to explicitly check?
Check for existance of script
fnirt,
The performance hit is essentially the same either way you execute a script.
So, you're idea is to attempt to execute the script and if the error is tripped then you'll know the script does not exists and your scrape goes merrily on.
If it works like you expect, I say go for it. If your attempt to execute fails it shouldn't have a negative impact on your session. Not a bad solution.
-Scott
Check for existance of script
Ok, here's a followup:
As far as efficiency and performance, is this an "expensive" thing to be doing or pretty clean:
{
session.executeScript("thisscrape.required");
}
catch( Exception e )
{
session.log( "An internal error occurred while checking requiredness: " + e.getMessage() );
}
Check for existance of script
fnirt,
There is not (unless it's undocumented). Perhaps you could check for the "theory" of the existence of the script by referencing a representative construct like a hashtable you generate simply for the purposes of this need to reference your scripts.
Speaking not as the developer, occasionally I'll be let in on undocumented methods here and there. Since screen-scraper is basically built on the Java framework you just might stab in the dark and find a way to check for the existence of a script as an object (referenced somehow using a key/value pair?)
Tread lightly when walking in the dark. :idea:
-Scott