Example #1
0
 private static bool IsUnwantedLanguageDiv(HtmlNode div)
 {
     return div.GetAttributeValue("class", "").Equals("libCScode")
            &&
            !div.Element("div").Element("div").InnerText.Trim().Equals("c#",
                                                                       StringComparison.CurrentCultureIgnoreCase);
 }
        private void ProcessElem(HtmlNode liElem, List<SongInRankingContract> songs)
        {
            var spanElem = liElem.Element("span");

            if (spanElem == null)
                return;

            var strongElem = spanElem.SelectSingleNode("strong");

            if (strongElem == null)
                return;	// List has items without order number (like "ED song") - skip them

            var orderNumStr = strongElem.InnerText;
            var numPart = numRegex.Match(orderNumStr);
            var orderNum = int.Parse(numPart.Value);

            var aElem = liElem.Element("a");
            var nicoUrl = aElem.Attributes["href"].Value;
            var nicoId = GetNicoId(nicoUrl);

            var name = aElem.InnerText;

            songs.Add(new SongInRankingContract { Name = name, NicoId = nicoId, SortIndex = orderNum });

            foreach (var childElem in liElem.ChildNodes)
                ProcessElem(childElem, songs);
        }
 private static void ApplyComment(HtmlNode dayNoteDiv, DayNote dayNote)
 {
     var commentNode = dayNoteDiv.Element("span");
     dayNote.Comment = commentNode != null
         ? HttpUtility.HtmlDecode(commentNode.InnerText)
         : null;
 }
Example #4
0
        public MsdnIssue(int year, HtmlNode tableCellCover)
        {
            var cellInfos = tableCellCover.NextSibling;

            Year = year;
            Title = cellInfos.Element("strong").InnerText;
            CoverImageUrl = new Uri(tableCellCover.Descendants("img").First().GetAttributeValue("src", ""));
            _url = new Uri(tableCellCover.Element("a").GetAttributeValue("href", ""));
        }
Example #5
0
        public static SteamGame GameFromDiv(HtmlNode divElement)
        {
            var gamePageLink = divElement.Element("a");
            var title = gamePageLink.GetAttributeValue("title", "Error");
            var url = gamePageLink.GetAttributeValue("href", "Error");

            var priceDiv = divElement.Descendants("div").Where(d => d.GetAttributeValue("class", "") == "price").First();
            var normalPriceSpan = priceDiv.Descendants("span").Where(s => s.GetAttributeValue("class", "") == "was").First();
            var salePriceSpan = priceDiv.Descendants("span").Where(s => s.GetAttributeValue("class", "") == "").First();

            var normalPrice = ParsePrice(normalPriceSpan);
            var salePrice = ParsePrice(salePriceSpan);

            return new SteamGame(title, url, normalPrice, salePrice);
        }
		private HtmlNode FindTracklistRow(HtmlDocument doc, HtmlNode row) {

			// Find the first table row on the page
			if (row == null)
				row = doc.DocumentNode.SelectSingleNode(".//div[@class='postcontent']/table/tr[1]");

			if (row != null) {

				while (row != null) {

					var cell = row.Element("td");

					if (cell != null && ContainsTracklist(cell))
						return row;

					row = row.NextSibling;

				}

			} else {

				// Legacy pages don't have a <table>, but <p> elements instead
				row = doc.DocumentNode.SelectSingleNode(".//div[@class='postcontent']/p[2]");

				while (row != null) {

					if (ContainsTracklist(row))
						return row;

					row = row.NextSibling;

				}

			}

			return null;

		}
        static Volume ParseVolumeSection(HtmlNode section)
        {
            Volume volume = new Volume();
            volume.CoverImageUri = section.FirstChildClass("cover").Element("img").GetAttributeValue("src", string.Empty);
            volume.Title = WebUtility.HtmlDecode(section.FirstChildClass("info").InnerText);
            volume.Label = ExtractLabel(volume.Title);
            volume.Title = RemoveLabel(volume.Title);
            volume.Chapters = section.Element("ul").Elements("li").Select(li =>
            {
                var cpt = new ChapterProperties();
                var a = li.Element("a");
                var pos = ParseIDFromReadLink(a.GetAttributeValue("href", String.Empty));
                cpt.Id = pos.ChapterId;
                cpt.ParentVolumeId = pos.VolumeId;
                cpt.ParentSeriesId = pos.SeriesId;
                cpt.Title = a.InnerText;
                return cpt;
            }).ToList();

            if (volume.Chapters.Count > 0)
            {
                volume.Id = volume.Chapters[0].ParentVolumeId;
                volume.ParentSeriesId = volume.Chapters[0].ParentSeriesId;
            }

            for (int chapterIdx = 0; chapterIdx < volume.Chapters.Count; chapterIdx++)
            {
                var chapter = volume.Chapters[chapterIdx];
                chapter.ChapterNo = chapterIdx;
                //chapter.ParentVolumeId = vol.Id;
                chapter.ParentVolumeId = volume.Id;
                if (chapterIdx > 0)
                {
                    //chapter.PrevChapter = vol.Chapters[chapterIdx - 1];
                    chapter.PrevChapterId = volume.Chapters[chapterIdx - 1].Id;
                }
                if (chapterIdx < volume.Chapters.Count - 1)
                {
                    //chapter.NextChapter = vol.Chapters[chapterIdx + 1];
                    chapter.NextChapterId = volume.Chapters[chapterIdx + 1].Id;
                }
            }
            return volume;
        }
        // a href = "/book/detail?id=*"
        private static BookItem ParseBookItem(HtmlNode a)
        {
            var book = new BookItem();
            book.HyperLinkUri = a.GetAttributeValue("href", null);
            book.CoverImageUri = a.Element("img")?.GetAttributeValue("src", null);
            book.Title = a.FirstChildClass("title")?.InnerText;

            if (book.Title == null)
                book.Title = CleanText(a.InnerText);

            book.Subtitle = a.FirstChildClass("status")?.InnerText;
            book.SeriesId = ParseIDFromBookLink(book.HyperLinkUri);
            return book;
        }
Example #9
0
        private static HtmlNode ClearNodes(HtmlNode JobOfferElement)
        {
            //var trsToRemove = JobOfferElement.Elements("tr").ToList();

            //JobOfferElement.RemoveChild(trsToRemove[0]);
            //JobOfferElement.RemoveChild(trsToRemove[1]);
            //JobOfferElement.RemoveChild(trsToRemove[2]);

            JobOfferElement = RemoveDescendants(JobOfferElement, new string[] { "a", "img", "script", "style" });
            JobOfferElement.RemoveChild(JobOfferElement.Element("tr"));

            var trS = JobOfferElement.Elements("tr").ToList();

            bool removeNext = false;
            foreach (var item in trS)
            {
                if (removeNext == false)
                {
                    if (item.Descendants().Where(
                        d => (d.Attributes.Contains("class") &&
                            d.Attributes["class"].Value.Contains("button_new"))
                            ).Count() > 0)
                    {
                        removeNext = true;
                    }
                }
                if (removeNext == true)
                {
                    JobOfferElement.RemoveChild(item);
                }
            }

            return JobOfferElement;
        }
Example #10
0
        public void PopulateTeam(HtmlNode table, ref List<Cast> castList, string roleName)
        {
            var tbody = table.Element("tbody");

            if (tbody != null)
            {
                var tr = tbody.Elements("tr");
                if (tr != null)
                {
                    foreach (HtmlNode row in tr)
                    {
                        var nameNodes = row.Elements("td");
                        if (nameNodes != null)
                        {
                            Cast cast = new Cast();
                            cast.role = roleName.Replace("&nbsp;", " ");

                            foreach (HtmlNode node in nameNodes)
                            {
                                if (node.Attributes["class"] != null && node.Attributes["class"].Value == "name")
                                {
                                    var link = node.Element("a");
                                    cast.name = link.InnerText.Replace("'", string.Empty).Replace("&", string.Empty).Trim();

                                    if (link.Attributes["href"] != null)
                                    {
                                        cast.link = link.Attributes["href"].Value;
                                    }
                                }
                                else if (node.Attributes["class"] != null && node.Attributes["class"].Value == "credit")
                                {
                                    cast.charactername = node.InnerText.Replace("'", string.Empty).Replace("&", string.Empty).Trim();
                                }
                            }

                            castList.Add(cast);
                        }
                    }
                }
            }
        }
        private VideoInfo getVideoInfo(HtmlNode itemDiv)
        {
            VideoInfo video = new VideoInfo();

            video.VideoUrl = itemDiv.Elements("div").Last().GetAttributeValue("arte_vp_url", "");
            video.Length = itemDiv.Descendants("div").Where(d => d.GetAttributeValue("class", "").Contains("badge-holder")).FirstOrDefault().Element("div").NextSibling.InnerText.Trim().Trim('"').Trim();
            video.Airdate = itemDiv.Descendants("p").FirstOrDefault().ChildNodes.LastOrDefault().InnerText.Trim();
            video.Title = itemDiv.Descendants("h3").FirstOrDefault().InnerText.Trim();
            video.Thumb = itemDiv.Element("img").GetAttributeValue("src", "");
            video.Description = itemDiv.GetAttributeValue("data-description", "");

            return video;
        }
Example #12
0
 private static Tuple<HtmlNode, HtmlNode> ExtractPayload(HtmlNode tableNode, int titleIndex, int ratingIndex)
 {
     var row = tableNode.Element("tr");
     if (row == null)
         return null;
     var cells = row.Elements("td").ToList();
     if (cells.Count < 2)
         return null;
     var linkNode = cells[titleIndex].ChildNodes.FirstOrDefault(n => n.Name == "a");
     if (linkNode == null)
         return null;
     var linkNodeClass = linkNode.Attributes["class"];
     if (linkNodeClass == null || linkNodeClass.Value != "animetitle")
         return null;
     return Tuple.Create(linkNode, cells[ratingIndex]);
 }