Exemple #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;
                root_url     = string.Join("/", URLText.Text.Split(new char[] { '/' }, 4), 0, 3);

                if (driverCheck.IsChecked == false)
                {
                    var html = NetCommon.DownloadString(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);
            }
        }
        public static void ProcessManazero(string url)
        {
            Task.Run(() =>
            {
                var sw = new SeleniumWrapper();

                MainWindow.Instance.Fade_MiddlePopup(true, "접속중...");
                sw.Navigate(url);
                try { sw.ClickXPath("//a[@class='maia-button maia-button-primary']"); } catch { }

                var title    = ManazeroParser.ParseTitle(sw.GetHtml());
                var articles = ManazeroParser.ParseArticles(sw.GetHtml());
                MainWindow.Instance.ModifyText_MiddlePopup($"가져오는중...[0/{articles.Count}]");

                for (int i = 0; i < articles.Count; i++)
                {
                    sw.Navigate(articles[i].ArticleLink);
                    if (i == 0)
                    {
                        try { sw.ClickXPath("//a[@class='maia-button maia-button-primary']"); } catch { }
                    }
                    articles[i].ImagesLink = ManazeroParser.ParseImages(sw.GetHtml());
                    MainWindow.Instance.ModifyText_MiddlePopup($"가져오는중...[{i + 1}/{articles.Count}]");
                }
                sw.Close();

                int count = 0;
                foreach (var article in articles)
                {
                    string dir = Path.Combine(Path.Combine(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "manazero"), DeleteInvalid(title)), DeleteInvalid(article.Title));
                    Directory.CreateDirectory(dir);

                    var se     = Koromo_Copy.Interface.SemaphoreExtends.MakeDefault();
                    se.Referer = url;

                    count += article.ImagesLink.Count;
                    DownloadSpace.Instance.RequestDownload($"manazero: {article.Title}",
                                                           article.ImagesLink.ToArray(),
                                                           article.ImagesLink.Select(x => Path.Combine(dir, HttpUtility.UrlDecode(HttpUtility.UrlDecode(x.Split('/').Last())))).ToArray(),
                                                           se,
                                                           dir + '\\',
                                                           null
                                                           );
                }

                MainWindow.Instance.FadeOut_MiddlePopup($"{count}개({articles.Count} 작품) 항목 다운로드 시작...");
            });
        }
        public static void ProcessPinterest(string url)
        {
            Task.Run(async() =>
            {
                string user = Regex.Match(url, "pinterest.co.kr/(.*?)/").Groups[1].Value;
                var sw      = new SeleniumWrapper();

                MainWindow.Instance.Fade_MiddlePopup(true, "접속중...");
                sw.Navigate(url);
                sw.WaitComplete();
                sw.ClickXPath("//div[@data-test-id='loginButton']");
                MainWindow.Instance.ModifyText_MiddlePopup("로그인중...");
                sw.SendKeyId("email", Settings.Instance.Pinterest.Id);
                sw.SendKeyId("password", Settings.Instance.Pinterest.Password);
                sw.ClickXPath("//div[@data-test-id='registerFormSubmitButton']");
                await Task.Delay(10000);
                sw.WaitComplete();
                sw.Navigate($"https://www.pinterest.co.kr/{user}/pins/");
                await Task.Delay(5000);
                sw.WaitComplete();

                List <string> images = new List <string>();
                string last;
                do
                {
                    last = sw.GetHeight();
                    sw.ScrollDown();
                    await Task.Delay(2000);

                    foreach (var image in PinParser.ParseImage(sw.GetHtml()))
                    {
                        if (!images.Contains(image))
                        {
                            images.Add(image);
                            MainWindow.Instance.ModifyText_MiddlePopup($"가져오는중... [{images.Count}]");
                        }
                    }
                } while (last != sw.GetHeight());

                int height = Convert.ToInt32(sw.GetHeight());
                for (int i = 0; i < height; i += 50)
                {
                    sw.Scroll(i);
                    await Task.Delay(1);
                    foreach (var image in PinParser.ParseImage(sw.GetHtml()))
                    {
                        if (!images.Contains(image))
                        {
                            if (!images.Contains(image))
                            {
                                images.Add(image);
                                MainWindow.Instance.ModifyText_MiddlePopup($"재 수집중... [{images.Count}]");
                            }
                        }
                    }
                }

                sw.Close();

                string dir = Path.Combine(Settings.Instance.Pinterest.Path, DeleteInvalid(user));
                Directory.CreateDirectory(dir);

                var se     = Koromo_Copy.Interface.SemaphoreExtends.MakeDefault();
                se.Referer = "https://www.pinterest.co.kr/";

                DownloadSpace.Instance.RequestDownload($"pinterest: {user}",
                                                       images.ToArray(),
                                                       images.Select(x => Path.Combine(dir, x.Split('/').Last())).ToArray(),
                                                       se,
                                                       dir + '\\',
                                                       null
                                                       );
                MainWindow.Instance.FadeOut_MiddlePopup($"{images.Count}개 항목 다운로드 시작...");
            });
        }