Пример #1
0
        static void Main(string[] args)
        {
            var scraper = new CasperScraper();

            var script = AppDomain.CurrentDomain.BaseDirectory + @"\scripts\test.js";

            var result = scraper.Execute(script, new { term = "rulee" });

            Console.WriteLine(result);
        }
Пример #2
0
        static void Main(string[] args)
        {
            var decodedArgs = args.Select(x => HttpUtility.UrlDecode(x)).ToList();

            var scriptFile     = decodedArgs[0];
            var resultFile     = decodedArgs[1];
            var jsonArgument   = decodedArgs[2];
            var outputEncoding = decodedArgs[3];
            var timeout        = decodedArgs[4];
            var proxyLog       = (decodedArgs[5] == "true");

            if (proxyLog)
            {
                var source = typeof(Program).Assembly.ManifestModule.Name;

                LogFactory.GetLogger().Debug(source, string.Join("|", decodedArgs));
            }

            try
            {
                var scraper = new CasperScraper();

                if (!string.IsNullOrWhiteSpace(outputEncoding))
                {
                    scraper.OutputEncoding = Encoding.GetEncoding(outputEncoding);
                }

                if (!string.IsNullOrWhiteSpace(timeout))
                {
                    scraper.ExecuteTimeout = TimeSpan.Parse(timeout);
                }

                var scrapeResult = scraper.Execute(scriptFile, jsonArgument);

                File.WriteAllText(resultFile, scrapeResult);
            }
            catch (Exception ex)
            {
                File.WriteAllText(resultFile, ex.ToString());
            }
        }