Esempio n. 1
0
 private void AddItemIntoTreeView(ObservableCollection <MenuTreeItem> root, MenuTreeItem child)
 {
     trvMain.Dispatcher.Invoke(new Action(() =>
     {
         root.Add(child);
     }));
 }
Esempio n. 2
0
        private void btnLoadData_Click(object sender, RoutedEventArgs e)
        {
            Thread t = new Thread(
                () =>
            {
                var url         = "Learn";
                var html        = GetHtml(url);
                var stringRegex = @"(?<=<div class=""col-md-6 col-xl-3"">).*?(?=<div class=""col-md-6 col-xl-3"">)";

                var coursesHtml = Regex.Matches(html, stringRegex, RegexOptions.Singleline);
                foreach (var item in coursesHtml)
                {
                    string getCourseNameRegex = @"(?<=h4 class=""font-size-default font-w600 mb-10 text-overflow-dot"" title="")(.*?)(?="">)";
                    string getCourseLinkRegex = @"(?<=data-href=""/).*?(?="" data-action)";
                    string courseName         = Regex.Match(item.ToString(), getCourseNameRegex).ToString();
                    string courseLink         = Regex.Match(item.ToString(), getCourseLinkRegex).ToString();

                    MenuTreeItem menu = new MenuTreeItem();
                    menu.Name         = courseName;
                    menu.URL          = courseLink;

                    AddItemIntoTreeView(TreeItems, menu);

                    string courseID = courseLink.Substring(courseLink.LastIndexOf('-') + 1);

                    string htmlCourse       = GetHtml("https://www.howkteam.vn/learn/lecturelist?courseId=" + courseID);
                    string lectureRegex     = @"(?<=<span class=""font-w600"">).*?(?=</a>)";
                    string lectureLinkRegex = @"(?<=href=""/).*?(?="")";
                    var lecturesHtml        = Regex.Matches(htmlCourse, lectureRegex, RegexOptions.Singleline);
                    var lectureLinks        = Regex.Matches(htmlCourse, lectureLinkRegex, RegexOptions.Singleline);
                    for (int i = 0; i < lecturesHtml.Count; i++)
                    {
                        var lectureName = lecturesHtml[i].ToString().Replace(@"</span>
                    ", "");
                        var lectureLink = lectureLinks[i].ToString().Trim();
                        var lecture     = new MenuTreeItem();
                        lecture.Name    = lectureName;
                        lecture.URL     = lectureLink;
                        AddItemIntoTreeView(menu.Items, lecture);
                    }
                }
            }
                );

            t.Start();
        }