Exemplo n.º 1
0
        private void URLButton_Click(object sender, RoutedEventArgs e)
        {
            if (original_url == URLText.Text)
            {
                HTMLList.DataContext = new CustomCrawlerDataGridViewModel(GetLoadResults());
                return;
            }
            try
            {
                original_url = URLText.Text;
                try { root_url = string.Join("/", URLText.Text.Split(new char[] { '/' }, 4), 0, 3); } catch { }

                if (driverCheck.IsChecked == false)
                {
                    string html;
                    if (!File.Exists(URLText.Text))
                    {
                        var client = NetCommon.GetDefaultClient();
                        if (EucKR.IsChecked == true)
                        {
                            client.Encoding = Encoding.GetEncoding(51949);
                        }
                        html = client.DownloadString(URLText.Text);
                    }
                    else
                    {
                        html = File.ReadAllText(URLText.Text);
                    }
                    tree = new HtmlTree(html);
                    tree.BuildTree();
                    HTMLList.DataContext = new CustomCrawlerDataGridViewModel(GetLoadResults());
                }
                else
                {
                    var driver = new SeleniumWrapper();
                    driver.Navigate(URLText.Text);
                    tree = new HtmlTree(driver.GetHtml());
                    tree.BuildTree();
                    driver.Close();
                    HTMLList.DataContext = new CustomCrawlerDataGridViewModel(GetLoadResults());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 2
0
        public SeleniumWrapper()
        {
            var driver_path     = Path.Combine(Directory.GetCurrentDirectory(), "chromedriver.exe");
            var driver_zip_path = Path.Combine(Directory.GetCurrentDirectory(), "chromedriver.zip");

            if (!File.Exists(driver_path))
            {
                NetCommon.GetDefaultClient().DownloadFile("https://chromedriver.storage.googleapis.com/72.0.3626.7/chromedriver_win32.zip", driver_zip_path);

                var zip = ZipFile.Open(driver_zip_path, ZipArchiveMode.Read);
                zip.Entries[0].ExtractToFile(driver_path);
                zip.Dispose();
                File.Delete(driver_zip_path);
            }
            var chromeDriverService = ChromeDriverService.CreateDefaultService($"{Directory.GetCurrentDirectory()}");

            chromeDriverService.HideCommandPromptWindow = true;
            var chrome = new ChromeOptions();

            chrome.AddArgument("--headless");
            driver = new ChromeDriver(chromeDriverService, chrome);
        }