001package Torello.Browser; 002 003import java.net.URL; 004import java.io.IOException; 005import Torello.HTML.Scrape; 006 007public class ReadAPI 008{ 009 /** 010 * You may use this method (if you so choose, for whatever reason) to retrieve the Remote 011 * Debugging Port API from Google. This method will return a (very long) JSON-File, as a 012 * {@code java.lang.String} 013 * 014 * @param port This should be the port that was used to start the server. This is, by default, 015 * port {@code 9223}. 016 * 017 * @return A very-long JSON-{@code String} containing the currently-exported API that your 018 * web-browser provides. 019 * 020 * @throws IOException If there are problems sending this request, or retrieving the response, 021 * this throws. 022 */ 023 public static String readAPIFromServer(Integer port) throws IOException 024 { 025 if (port == null) port = 9222; 026 027 final String urlStr = "http://127.0.0.1:" + port + "/json/protocol"; 028 final URL url = new URL(urlStr); 029 030 System.out.println("Querying WS Server for JSON\n" + url); 031 032 // NOTE: This is a very large JSON File - more than 20,000 lines of text 033 return Scrape.scrapePage(url); 034 } 035}