Exemple #1
0
        /// <summary>
        /// Extract the Links
        /// </summary>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <returns>
        /// All Anchors on the Page
        /// </returns>
        public static List<LinkItem> ListAllLinks(string page)
        {
            var linkList = new List<LinkItem>();

            if (CacheController.Instance().UserSettings.CurrentForumUrl.Contains(@"halohul.com"))
            {
                var hrefMatchNew = Regex.Matches(page, @"src=\""(.*?)\""", RegexOptions.IgnoreCase);

                linkList.AddRange(
                    hrefMatchNew.Cast<Match>().Select(match => new LinkItem { Href = match.Groups[1].Value }));
            }
            else
            {
                var linkMatch = Regex.Matches(page, @"(<a.*?>.*?</a>)", RegexOptions.Multiline);

                foreach (Match match in linkMatch)
                {
                    var value = match.Groups[1].Value;
                    var item = new LinkItem();

                    var hrefMatch = Regex.Match(value, @"href=\""(.*?)\""", RegexOptions.IgnoreCase);

                    if (hrefMatch.Success)
                    {
                        item.Href = hrefMatch.Groups[1].Value;
                    }

                    var thumbNailMatch = Regex.Match(value, @"src=\""(.*?)\""", RegexOptions.IgnoreCase);

                    if (!thumbNailMatch.Success)
                    {
                        continue;
                    }

                    item.Text = thumbNailMatch.Groups[1].Value;

                    linkList.Add(item);
                }
           }

            return linkList;
        }
Exemple #2
0
        /// <summary>
        /// Extract the Image
        /// </summary>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <returns>
        /// All Anchors on the Page
        /// </returns>
        public static List<LinkItem> ListAllImages(string page)
        {
            var anchorList = new List<LinkItem>();

            var linkImageMatch = Regex.Matches(page, @"^(?!<a.*?>)(<img.*?>)", RegexOptions.IgnoreCase);

            foreach (Match match in linkImageMatch)
            {
                var value = match.Groups[1].Value;
                var item = new LinkItem();

                var hrefMatch = Regex.Match(value, @"src=\""(.*?)\""", RegexOptions.IgnoreCase);

                if (hrefMatch.Success)
                {
                    item.Href = hrefMatch.Groups[1].Value;
                }

                anchorList.Add(item);
            }

            return anchorList;
        }