示例#1
0
 public void SetUp()
 {
     browshot = new BrowshotClient("vPTtKKLBtPUNxVwwfEKlVvekuxHyTXyi"); // test1
 }
示例#2
0
        static void Main(string[] args)
        {
            string url = LoadSetting("url", String.Empty);
            string key = LoadSetting("key", String.Empty);

            string size = LoadSetting("size", "screen");
            int delay = LoadSetting("delay", 5);
            int flash_delay = LoadSetting("flash_delay", 5);
            int quality = LoadSetting("quality", 90);
            int instance_id = LoadSetting("instance", 65);
            int cache = LoadSetting("cache", 8600);
            int shots = LoadSetting("shots", 1);
            int shot_interval = LoadSetting("shot_interval", 5);
            int screen_width = LoadSetting("screen_width", 0);
            int screen_height = LoadSetting("screen_height", 0);
            string referrer = LoadSetting("referrer", String.Empty);
            string script = LoadSetting("script", String.Empty);
            string post_data = LoadSetting("post_data", String.Empty);

            // thumbnail
            int width = LoadSetting("width", 0);
            int height = LoadSetting("height", 0);
            string file = LoadSetting("file", String.Empty);
            string format = LoadSetting("format", "png");

            bool show_help = false;

            //OptionSet option_set = new OptionSet()
            //.Add("?|help|h", "Prints out the options.", v => show_help = v != null)
            //.Add("u|url=", "the {URL} for the screenshot", v => url = v )
            //.Add("s|shots=", "the number of {SHOTS} of the same page.", v => shots = v );

            var p = new OptionSet() {
                { "u|url=", "the {URL} for the screenshot",
                  v =>  url = v },
                { "k|key=", "your API {KEY}\n" + String.Format("default = {0}", key),
                   v =>  key = v },
                { "f|file=", "{FILENAME} to use for the thumbnail images\n" + String.Format("default = {0}", file),
                   v =>  file = v },
                { "i|instance=",
                    "{INSTANCE_ID} to use\n" + String.Format("default = {0}", instance_id),
                  (int v) => instance_id = v },
                { "z|size=",
                    "the screenshot {SIZE}, 'page' or 'screen'\n" + String.Format("default = {0}", size),
                  v => size = v },
                { "d|delay=",
                    "number of {SECONDS} to wait after the page is loaded\n" + String.Format("default = {0}", delay),
                  (int v )=> delay = v },
                { "fd|flash_delay=",
                    "number of {SECONDS} to wait if Flash objects are present\n" + String.Format("default = {0}", flash_delay),
                  (int v )=> flash_delay = v },
                { "o|format=",
                    "the image {FORMAT} of the screenshot, 'png' or 'jpeg'\n" + String.Format("default = {0}", format),
                  v => format = v },
                { "q|quality=",
                    "JPEG image {QUALITY} of the screenshot\n" + String.Format("Optional, default = {0}", quality),
                  (int v) => quality = v },
                { "s|shots=",
                    "the number of {SHOTS} of the same page\n" + String.Format("Optional, default = {0}", shots),
                  (int v) => shots = v },
                { "si|shot_interval=",
                    "the number of {SECONDS} between 2 screenshots of the same page\n" + String.Format("Optional, default = {0}", shot_interval),
                  (int v) => shot_interval = v },
                { "c|cache=",
                    "get a previous screenshots if done within {SECONDS}\n" + String.Format("default = {0}", cache),
                  (int v) => cache = v },
                { "w|width=",
                    "thumbnail {WIDTH}\n" + String.Format("default = {0}", width),
                  (int v) => width = v },
               { "e|height=",
                    "thumbnail {HEIGHT}\n" + String.Format("default = {0}", height),
                  (int v) => height = v },
               { "sw|screen_width=",
                    "browser screen {WIDTH}\n" + String.Format("default = {0}", screen_width),
                  (int v) => screen_width = v },
               { "sh|screen_height=",
                    "browser screen {HEIGHT}\n" + String.Format("default = {0}", screen_height),
                  (int v) => screen_height = v },
               { "referrer=",
                    "{REFERRER} Url\n" + String.Format("default = {0}", referrer),
                  v => referrer = v },
               { "script=",
                    "{JAVASCRIPT} Url to inject in the page\n" + String.Format("default = {0}", script),
                  v => script = v },
               { "post_data=",
                    "{POST DATA} for a POST request\n" + String.Format("default = {0}", post_data),
                  v => script = v },
                /*{ "v", "increase debug message verbosity",
                  v => { if (v != null) ++verbosity; } },*/
                { "h|help|?",  "show the list of options",
                  v => show_help = v != null },
            };

            List<string> extra;
            try {
                extra = p.Parse (args);
            }
            catch (OptionException e) {
                Console.Write ("browshot-cmd.exe: ");
                Console.WriteLine (e.Message);
                Console.WriteLine ("Try `browshot-cmd.exe --help' for more information");
                return;
            }

            if (show_help)
            {
                ShowHelp(p);
                return;
            }

            if(url == String.Empty)
            {
                Console.WriteLine("Missing URL");
                ShowHelp(p);
                return;
            }

            if (key == String.Empty)
            {
                Console.WriteLine("Missing API key");
                ShowHelp(p);
                return;
            }

            /*if (file == String.Empty)
            {
                Console.WriteLine("Missing file name");
                ShowHelp(p);
                return;
            }*/

            browshot = new BrowshotClient(key, true);

            Hashtable arguments = new Hashtable();
            arguments.Add("instance_id", instance_id);
            arguments.Add("size", size);
            arguments.Add("cache", cache);
            arguments.Add("shots", shots);
            arguments.Add("delay", delay);
            arguments.Add("flash_delay", flash_delay);
            arguments.Add("screen_width", screen_width);
            arguments.Add("screen_height", screen_height);
            arguments.Add("shot_interval", shot_interval);
            arguments.Add("format", format);
            arguments.Add("quality", quality);
            arguments.Add("referrer", referrer);
            arguments.Add("script", script);
            arguments.Add("post_data", post_data);
            // ...
            arguments.Add("width", width);
            arguments.Add("height", height);
            arguments.Add("file", file);

            start(url, arguments);
        }
示例#3
0
 public void SetUp()
 {
     browshot = new BrowshotClient("API_KEY");
 }