本文整理汇总了C#中HtmlAgilityPack.HtmlNode.Element方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlNode.Element方法的具体用法?C# HtmlNode.Element怎么用?C# HtmlNode.Element使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlAgilityPack.HtmlNode
的用法示例。
在下文中一共展示了HtmlNode.Element方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsUnwantedLanguageDiv
private static bool IsUnwantedLanguageDiv(HtmlNode div)
{
return div.GetAttributeValue("class", "").Equals("libCScode")
&&
!div.Element("div").Element("div").InnerText.Trim().Equals("c#",
StringComparison.CurrentCultureIgnoreCase);
}
示例2: ProcessElem
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);
}
示例3: ApplyComment
private static void ApplyComment(HtmlNode dayNoteDiv, DayNote dayNote)
{
var commentNode = dayNoteDiv.Element("span");
dayNote.Comment = commentNode != null
? HttpUtility.HtmlDecode(commentNode.InnerText)
: null;
}
示例4: MsdnIssue
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", ""));
}
示例5: GameFromDiv
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);
}
示例6: FindTracklistRow
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;
}
示例7: ParseVolumeSection
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;
}
示例8: ParseBookItem
// 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;
}
示例9: ClearNodes
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;
}
示例10: PopulateTeam
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(" ", " ");
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);
}
}
}
}
}
示例11: getVideoInfo
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;
}
示例12: ExtractPayload
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]);
}