Executing javascript in java - Opening a URL and getting links

后端 未结 5 1953
醉话见心
醉话见心 2020-12-19 18:57
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.io.FileReader;

public class Main {

    public static void main(String[] args         


        
5条回答
  •  醉酒成梦
    2020-12-19 19:31

    According to the documentation:

    The window object represents an open window in a browser.

    Since you are not executing your script in a browser, the window object is not defined.

    You can read the URL using the URL/URLConnecion classes and feed it to the ScriptEngine. There is a tutorial here.

提交回复
热议问题