How To Execute Javascript On A Webpage Using Java
I am establishing a HttpUrlConnection with a webpage . Now I have javascript snippet that I want to execute on this webpage . How can I do this ?
Solution 1:
You could try :
privatestaticScriptEngineManagermgr=null;
privatestaticScriptEngineengine=null;
mgr = newScriptEngineManager();
engine = mgr.getEngineByName("JavaScript");
Objecteval= engine.eval(s); // s is javascript code
Solution 2:
Since Javascript needs some kind of Virtual Machine to run in - usually provided by browsers or programms which act like browsers (so called headless browsers), you have to use some kind of "browsing engine" (so to say) to run the page in. Perhaps WebEngine may be worth a look.
Post a Comment for "How To Execute Javascript On A Webpage Using Java"