1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package Torello.Browser;

import java.net.URL;
import java.io.IOException;
import Torello.HTML.Scrape;

public class ReadAPI
{
    /**
     * You may use this method (if you so choose, for whatever reason) to retrieve the Remote
     * Debugging Port API from Google.  This method will return a (very long) JSON-File, as a
     * {@code java.lang.String}
     * 
     * @param port This should be the port that was used to start the server.  This is, by default,
     * port {@code 9223}.
     * 
     * @return A very-long JSON-{@code String} containing the currently-exported API that your
     * web-browser provides.
     * 
     * @throws IOException If there are problems sending this request, or retrieving the response,
     * this throws.
     */
    public static String readAPIFromServer(Integer port) throws IOException
    {
        if (port == null) port = 9222;

        final String    urlStr  = "http://127.0.0.1:" + port + "/json/protocol";
        final URL       url     = new URL(urlStr);

        System.out.println("Querying WS Server for JSON\n" + url);

        // NOTE: This is a very large JSON File - more than 20,000 lines of text
        return Scrape.scrapePage(url);
    }
}