コード例 #1
0
        public string GetPageSouce(string url)
        {
            PhantomJSDriverService service = PhantomJSDriverService.CreateDefaultService();

            service.AddArguments(new string[] {
                "--proxy-type=socks5", "--proxy=127.0.0.1:9050"
            });
            using (IWebDriver driver = new PhantomJSDriver(service))
            {
                try
                {
                    driver.Navigate().GoToUrl(url);
                    return(driver.PageSource);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    return(null);
                }
            }
        }
コード例 #2
0
        public bool DownloadSite(string url, string path)
        {
            //Process[] previous = Process.GetProcessesByName("tor");


            //if (previous != null && previous.Length > 0)
            //{

            //    foreach (Process process in previous)
            //        process.Kill();
            //}

            PhantomJSDriverService service = PhantomJSDriverService.CreateDefaultService();

            service.AddArguments(new string[] {
                "--proxy-type=socks5", "--proxy=127.0.0.1:9050"
            });
            using (IWebDriver driver = new PhantomJSDriver(service))
            {
                try
                {
                    driver.Navigate().GoToUrl(url);

                    using (FileStream fs = new FileStream(path, FileMode.Create))
                    {
                        using (StreamWriter sw = new StreamWriter(fs))
                        {
                            sw.Write(driver.PageSource);
                        }
                    }

                    return(true);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    return(false);
                }
            }
        }