本文整理汇总了C#中HtmlAgilityPack.HtmlNode.Descendants方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlNode.Descendants方法的具体用法?C# HtmlNode.Descendants怎么用?C# HtmlNode.Descendants使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlAgilityPack.HtmlNode
的用法示例。
在下文中一共展示了HtmlNode.Descendants方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseLine
protected static MatchInfos ParseLine(HtmlNode node)
{
MatchInfos infos = null;
infos = new MatchInfos();
var infosAdresse = node.Descendants("div").ElementAt(0).ChildNodes.ElementAt(1).Descendants("#text");
infos.Nom = infosAdresse.ElementAt(0).InnerText.Trim().Replace(" ", " ");
infos.Adresse = infosAdresse.ElementAt(1).InnerText.Trim().Replace(" ", " ");
infos.Ville = infosAdresse.ElementAt(2).InnerText.Trim().Replace(" ", " ");
if(node.ChildNodes.Where(item => item.Name == "div").Count() > 2)
{
var infosArbitres = node.ChildNodes.Where(item => item.Name == "div")
.ElementAt(2)
.ChildNodes
.ElementAt(1)
.Descendants("ul")
.ElementAt(0)
.Descendants("li");
foreach (var arbitre in infosArbitres)
{
infos.Arbitres.Add(HtmlEntity.DeEntitize(arbitre.InnerText.Trim()));
}
}
return infos;
}
示例2: FromPost
public static ForumUserEntity FromPost(HtmlNode postNode)
{
var user = new ForumUserEntity
{
Username =
WebUtility.HtmlDecode(
postNode.Descendants("dt")
.FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("author"))
.InnerHtml),
DateJoined =
DateTime.Parse(postNode.Descendants("dd")
.FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("registered"))
.InnerHtml)
};
var avatarTitle = postNode.Descendants("dd").FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Equals("title"));
var avatarImage = postNode.Descendants("dd").FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("title")).Descendants("img").FirstOrDefault();
if (avatarTitle != null)
{
user.AvatarTitle = WebUtility.HtmlDecode(avatarTitle.InnerText).WithoutNewLines().Trim();
}
if (avatarImage != null)
{
user.AvatarLink = FixPostHtmlImage(avatarImage.OuterHtml);
}
user.Id = Convert.ToInt64(postNode.DescendantsAndSelf("td").FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("userinfo")).GetAttributeValue("class", string.Empty).Split('-')[1]);
return user;
}
示例3: ExtractActivity
private static Activity ExtractActivity(HtmlNode node, int index)
{
var name = node.Descendants("div")
.Where(div => div.GetAttributeValue("class", null) == "action_prompt")
.Select(div => HtmlEntity.DeEntitize(div.InnerText).Trim().Replace(" ", " "))
.FirstOrDefault();
if (name == null)
{
throw new InvalidDataException("Unable to find activity name");
}
return new Activity
{
Sequence = index,
Name = name,
Note = node.Descendants("li")
.Where(li => li.GetAttributeValue("class", null) == "stream_note")
.Select(li => HtmlEntity.DeEntitize(li.InnerText).Trim())
.FirstOrDefault(),
Sets = node.Descendants("li")
.Where(li => li.GetAttributeValue("class", null) != "stream_note")
.Select(ExtractSet)
.ToList()
};
}
示例4: GetTeamInfo
public Team GetTeamInfo(HtmlNode div)
{
HtmlNode[] links = div.Descendants("a").ToArray();
string name = div.Descendants("h1").First().InnerHtml;
name = name.Substring(name.IndexOf(" ") + 1, name.IndexOf("Roster") - 9);
string divName = links[3].NextSibling.InnerHtml;
divName = divName.Substring(1, divName.Length - 12);
Team team = new Team(name, new Division(divName));
string coachName = links[5].InnerHtml;
team.Coach = new Coach(coachName, team);
HtmlNode[] strongs = div.Descendants("strong").ToArray();
string arenaName = strongs[strongs.Length - 2].NextSibling.InnerHtml;
arenaName = arenaName.Substring(1, arenaName.IndexOf("&") - 2);
string arenaAttendance = strongs[strongs.Length - 1].NextSibling.InnerHtml;
arenaAttendance = arenaAttendance.Substring(1, arenaAttendance.IndexOf("(") - 2).Replace(",", string.Empty);
team.Arena = new Arena(arenaName, int.Parse(arenaAttendance));
return team;
}
示例5: Parse
public void Parse(HtmlNode rowNode)
{
Status =
rowNode.Descendants("td")
.FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Equals("status"))
.Descendants("img")
.FirstOrDefault()
.GetAttributeValue("src", string.Empty);
Icon =
rowNode.Descendants("td")
.FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Equals("icon"))
.Descendants("img")
.FirstOrDefault()
.GetAttributeValue("src", string.Empty);
Title =
rowNode.Descendants("td")
.FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Equals("title"))
.InnerText;
Sender = rowNode.Descendants("td")
.FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Equals("sender"))
.InnerText;
Date = rowNode.Descendants("td")
.FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Equals("date"))
.InnerText;
}
示例6: ParseMainArticle
public void ParseMainArticle(HtmlNode articleNode)
{
ArticleImage = articleNode.Descendants("img").FirstOrDefault().GetAttributeValue("src", string.Empty);
Title =
WebUtility.HtmlDecode(
articleNode.Descendants("h2").FirstOrDefault().Descendants("a").FirstOrDefault().InnerText);
ArticleLink =
articleNode.Descendants("h2")
.FirstOrDefault()
.Descendants("a")
.FirstOrDefault()
.GetAttributeValue("href", string.Empty);
Date =
articleNode.Descendants("span")
.FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("date"))
.InnerHtml;
Author =
WebUtility.HtmlDecode(
articleNode.Descendants("span")
.FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("author"))
.Descendants("a")
.FirstOrDefault()
.InnerText);
AuthorLink =
articleNode.Descendants("span")
.FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("author"))
.Descendants("a")
.FirstOrDefault()
.GetAttributeValue("href", string.Empty);
ArticleText = WebUtility.HtmlDecode(articleNode.Descendants("p").FirstOrDefault().InnerText);
}
示例7: ConvertSingleResult
public OverviewResult ConvertSingleResult(HtmlNode node)
{
OverviewResult result = new OverviewResult();
result.Url = node.Descendants("a").SingleOrDefault()?.Attributes["href"]?.Value;
result.Type = node.Descendants("h4").SingleOrDefault()?.InnerText;
result.Name = node.Descendants("h2").SingleOrDefault()?.InnerText;
return result;
}
示例8: ParseThread
public void ParseThread(HtmlNode popularThreadsNode)
{
Tag = popularThreadsNode.Descendants("img").FirstOrDefault().GetAttributeValue("src", string.Empty);
Title = WebUtility.HtmlDecode(popularThreadsNode.Descendants("a").FirstOrDefault().InnerText);
Id =
Convert.ToInt64(
popularThreadsNode.Descendants("a")
.FirstOrDefault()
.GetAttributeValue("href", string.Empty)
.Split('=')[1]);
}
示例9: FindRosterTable
private HtmlNode FindRosterTable(HtmlNode document)
{
IEnumerable<HtmlNode> blocks = document.Descendants("th").
Where(h => h.InnerHtml.IndexOf("2011-12 Roster") != -1);
if (blocks.Count() == 0)
{
blocks = document.Descendants("td").
Where(h => h.InnerHtml.IndexOf("2011-12 Roster") != -1);
}
return blocks.Last().Ancestors("table").First();
}
示例10: Parse
/// <summary>
/// Parses a forum post in a thread.
/// </summary>
/// <param name="postNode">The post HTML node.</param>
public void Parse(HtmlNode postNode)
{
User = ForumUserEntity.FromPost(postNode);
HtmlNode postDateNode =
postNode.Descendants()
.FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Equals("postdate"));
string postDateString = postDateNode == null ? string.Empty : postDateNode.InnerText;
if (postDateString != null)
{
PostDate = postDateString.WithoutNewLines().Trim();
}
PostIndex = ParseInt(postNode.GetAttributeValue("data-idx", string.Empty));
var postId = postNode.GetAttributeValue("id", string.Empty);
if (!string.IsNullOrEmpty(postId) && postId.Contains("#"))
{
PostId =
Int64.Parse(postNode.GetAttributeValue("id", string.Empty)
.Replace("post", string.Empty)
.Replace("#", string.Empty));
}
else if (!string.IsNullOrEmpty(postId) && postId.Contains("post"))
{
PostId =
Int64.Parse(postNode.GetAttributeValue("id", string.Empty)
.Replace("post", string.Empty));
}
else
{
PostId = 0;
}
var postBodyNode = postNode.Descendants("td")
.FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Equals("postbody"));
this.FixQuotes(postBodyNode);
PostHtml = postBodyNode.InnerHtml;
HtmlNode profileLinksNode =
postNode.Descendants("td")
.FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Equals("postlinks"));
HtmlNode postRow =
postNode.Descendants("tr").FirstOrDefault();
if (postRow != null)
{
HasSeen = postRow.GetAttributeValue("class", string.Empty).Contains("seen");
}
User.IsCurrentUserPost =
profileLinksNode.Descendants("img")
.FirstOrDefault(node => node.GetAttributeValue("alt", string.Empty).Equals("Edit")) != null;
}
示例11: Parse
public void Parse(HtmlNode node)
{
try
{
Id = Convert.ToInt32(node.Descendants("input").First().GetAttributeValue("value", string.Empty));
ImageUrl = node.Descendants("img").First().GetAttributeValue("src", string.Empty);
Title = node.Descendants("img").First().GetAttributeValue("alt", string.Empty);
}
catch (Exception)
{
// If, for some reason, it fails to get an icon, ignore the error.
// The list view won't show it.
}
}
示例12: FromRapSheet
public static ForumUserRapSheetEntity FromRapSheet(HtmlNode rapSheetNode)
{
var rapSheet = new ForumUserRapSheetEntity();
List<HtmlNode> rapSheetData = rapSheetNode.Descendants("td").ToList();
rapSheet.PunishmentType = rapSheetData[0].Descendants("b").FirstOrDefault().InnerText;
rapSheet.Date = rapSheetData[1].InnerText;
rapSheet.HorribleJerk = rapSheetData[2].Descendants("a").FirstOrDefault().InnerText;
rapSheet.HorribleJerkId =
Convert.ToInt64(
rapSheetData[2].Descendants("a").FirstOrDefault().GetAttributeValue("href", string.Empty).Split('=')
[3]);
rapSheet.PunishmentReason = rapSheetData[3].InnerText;
rapSheet.RequestedBy = rapSheetData[4].Descendants("a").FirstOrDefault().InnerText;
rapSheet.RequestedById =
Convert.ToInt64(
rapSheetData[4].Descendants("a").FirstOrDefault().GetAttributeValue("href", string.Empty).Split('=')
[3]);
rapSheet.ApprovedBy = rapSheetData[5].Descendants("a").FirstOrDefault().InnerText;
rapSheet.ApprovedById =
Convert.ToInt64(
rapSheetData[5].Descendants("a").FirstOrDefault().GetAttributeValue("href", string.Empty).Split('=')
[3]);
return rapSheet;
}
示例13: LoadFromHtml
public bool LoadFromHtml(HtmlNode RootNode, DataLoadedEventArgs loadedEventArgs)
{
try
{
IEnumerable<HtmlNode> linkNodes = RootNode.Descendants("a");
foreach (HtmlNode linkNode in linkNodes)
{
MitbbsClubGroupLink clubGroupLink = new MitbbsClubGroupLink();
clubGroupLink.ParentUrl = Url;
if (clubGroupLink.LoadFromHtml(linkNode))
{
ClubGroupLinks.Add(clubGroupLink);
IsLoaded = true;
}
}
}
catch (Exception e)
{
IsLoaded = false;
loadedEventArgs.Error = e;
}
return IsLoaded;
}
示例14: SearchFromNode
private void SearchFromNode(HtmlNode baseNode)
{
var nodes = Enumerable.Empty<HtmlNode>();
if (!_html.DocumentNode.HasChildNodes)
ParseHtml();
if (chkXPath.IsChecked == true)
nodes = baseNode.SelectNodes(txtSearchTag.Text);
else
nodes = baseNode.Descendants(txtSearchTag.Text);
if (nodes == null) return;
listResults.Items.Clear();
foreach (var node in nodes)
{
var tr = new NodeTreeView { BaseNode = node };
var lvi = new ListBoxItem();
var pnl = new StackPanel();
pnl.Children.Add(new Label
{
Content =
string.Format("id:{0} name:{1} children{2}", node.Id, node.Name,
node.ChildNodes.Count),
FontWeight = FontWeights.Bold
});
pnl.Children.Add(tr);
lvi.Content = pnl;
listResults.Items.Add(lvi);
}
tabControl1.SelectedItem = tabSearchResults;
}
示例15: GetSingleNodeByClassName
/// <summary>
/// NOTE: only works for ONE classname. If several TODO: create another method..
/// </summary>
/// <param name="tagName"></param>
/// <param name="className"></param>
/// <returns></returns>
public HtmlNode GetSingleNodeByClassName(string tagName, string className, HtmlNode node)
{
//TODO: fire a warning if any single methods would have produced more than one result, could mean the layout has changed
return node.Descendants()
.Where(x => x.Name == tagName && x.Attributes.Contains("class")
&& x.Attributes["class"].Value.Split().Contains(className)).SingleOrDefault();
}