本文整理汇总了C#中HtmlAgilityPack.Descendants方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlAgilityPack.Descendants方法的具体用法?C# HtmlAgilityPack.Descendants怎么用?C# HtmlAgilityPack.Descendants使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlAgilityPack
的用法示例。
在下文中一共展示了HtmlAgilityPack.Descendants方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetVacancyUrl
protected override string GetVacancyUrl(HtmlAgilityPack.HtmlNode div)
{
var vacancyHref = div.Descendants("a").Where(
d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("vacancy-title"))
.Select(d => d.Attributes["href"].Value).SingleOrDefault();
return BaseUrl + vacancyHref;
}
示例2: GetPosition
protected override string GetPosition(HtmlAgilityPack.HtmlNode div)
{
return div.Descendants("a").Where(
d => d.Attributes.Contains("class") &&
d.Attributes["class"].Value.Contains("rua-b-vacancy-title") || d.Attributes["class"].Value.Contains("jqKeywordHighlight")
).Select(d => d.InnerText).First();
}
示例3: GetNode
/// <summary>
///
/// </summary>
/// <param name="node"></param>
/// <param name="element"></param>
/// <param name="attribute"></param>
/// <param name="valuePortion"></param>
/// <returns></returns>
public static HtmlAgilityPack.HtmlNode GetNode(HtmlAgilityPack.HtmlNode node,
string element,
string attribute,
string valuePortion,
bool tryNull = false)
{
if(tryNull)
{
try
{
var _nodes = node.Descendants(element)
.Where(d => d.Attributes.Contains(attribute) && d.Attributes[attribute].Value.Contains(valuePortion));
if(_nodes != null && _nodes.Count() > 0)
{
var _node = _nodes.ToArray()[0];//.SingleOrDefault();
return _node;
}
}
catch { }
}
else
{
var _nodes = node.Descendants(element)
.Where(d => d.Attributes.Contains(attribute) && d.Attributes[attribute].Value.Contains(valuePortion));
if(_nodes != null && _nodes.Count() > 0)
{
var _node = _nodes.ToArray()[0];//.SingleOrDefault();
return _node;
}
}
return null;
}
示例4: GetInnerText
/// <summary>
///
/// </summary>
/// <param name="node"></param>
/// <param name="element"></param>
/// <param name="attribute"></param>
/// <param name="valuePortion"></param>
/// <returns></returns>
public static string GetInnerText(HtmlAgilityPack.HtmlNode node,
string element,
string attribute,
string valuePortion,
string defaultValue = "")
{
var _node = node.Descendants(element)
.Where(d => d.Attributes.Contains(attribute) && d.Attributes[attribute].Value.Contains(valuePortion))
.FirstOrDefault();
if(_node == null)
return defaultValue;
return _node.InnerText;
}
示例5: GetItemNodes
private IEnumerable<HtmlAgilityPack.HtmlNode> GetItemNodes(HtmlAgilityPack.HtmlNode node)
{
var itemscopeAttr = node.GetAttributeItemScope();
if (itemscopeAttr != null)
{
yield return node;
yield break;
}
foreach (var childNode in node.Descendants())
{
foreach (var item in GetItemNodes(childNode))
{
yield return item;
}
}
}
示例6: GetVacancyUrl
protected override string GetVacancyUrl(HtmlAgilityPack.HtmlNode row)
{
return row.Descendants("td").ElementAt(1).Descendants("a").Single().Attributes["href"].Value;
}
示例7: GetPosition
protected override string GetPosition(HtmlAgilityPack.HtmlNode row)
{
return row.Descendants("td").ElementAt(1).Descendants("a").Single().InnerText;
}
示例8: GetCompany
protected override string GetCompany(HtmlAgilityPack.HtmlNode row)
{
return row.Descendants("td").ElementAt(2).Descendants("em").Single().InnerText;
}
示例9: GetPosition
protected override string GetPosition(HtmlAgilityPack.HtmlNode row)
{
return row.Descendants("a").Where(
r => r.Attributes.Contains("class") && r.Attributes["class"].Value.Contains("title"))
.Select(r => r.InnerText).SingleOrDefault();
}
示例10: VideosForCategory
private List<VideoInfo> VideosForCategory(HtmlAgilityPack.HtmlNode node)
{
List<VideoInfo> videoList = new List<VideoInfo>();
var sections = node.Descendants("section").Where(s => s.GetAttributeValue("class", "") == "tv");
if (sections != null)
{
foreach (var section in sections)
{
var a = section.SelectSingleNode("a");
if (a != null)
{
VideoInfo video = new VideoInfo();
video.VideoUrl = baseUrl + a.GetAttributeValue("href", "");
var img = a.Descendants("img");
if (img != null && img.First() != null)
{
video.Thumb = img.First().GetAttributeValue("src", "");
video.Title = img.First().GetAttributeValue("alt", "");
}
var dd = a.Descendants("dd");
if (dd != null && dd.FirstOrDefault() != null)
video.Length = dd.FirstOrDefault().InnerText;
var h1 = a.Descendants("h1");
var descP = section.Descendants("p").Where(p => p.GetAttributeValue("class", "") == "ellipsis-lastline");
if (descP != null && descP.FirstOrDefault() != null)
video.Description = descP.FirstOrDefault().InnerText;
if (EnableAOSearch)
{
SerializableDictionary<string, string> other = new SerializableDictionary<string, string>();
var ul = section.SelectSingleNode("div[@class = 'details']/ul[@class = 'keywords']");
if (ul != null)
{
IEnumerable<HtmlNode> keyAs = ul.Descendants("a");
foreach (HtmlNode keyA in keyAs)
{
other.Add(keyA.GetAttributeValue("data-keyword", ""), keyA.GetAttributeValue("href", ""));
}
}
video.Other = other;
}
videoList.Add(video);
}
}
}
return videoList;
}
示例11: GetCompany
protected override string GetCompany(HtmlAgilityPack.HtmlNode div)
{
return div.Descendants("div").Where(
d => d.Attributes.Contains("class") &&
d.Attributes["class"].Value.Contains("companyName")).Select(d => d.FirstChild.InnerText).First();
}
示例12: GetVacancyHref
private static string GetVacancyHref(HtmlAgilityPack.HtmlNode div)
{
var vacancyHref = div.Descendants("a").Where(
d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("vacancyDescription"))
.Select(d => d.Attributes["href"].Value).SingleOrDefault();
return vacancyHref;
}
示例13: RemoveUnwantedTags
private void RemoveUnwantedTags(ConfigSection config, HtmlAgilityPack.HtmlNode parentNode)
{
if (parentNode != null && config != null && config.RemoveTags != null && config.RemoveTags.Count > 0)
{
parentNode.Descendants()
.Where(n => config.RemoveTags.Contains(n.Name.ToLowerInvariant()))
.ToList()
.ForEach(n => n.Remove());
}
}
示例14: GetNodeCollection
/// <summary>
///
/// </summary>
/// <param name="node"></param>
/// <param name="element"></param>
/// <param name="attribute"></param>
/// <param name="valuePortion"></param>
/// <returns></returns>
public static IEnumerable<HtmlAgilityPack.HtmlNode> GetNodeCollection(HtmlAgilityPack.HtmlNode node,
string element,
string attribute,
string valuePortion)
{
var _nodes = node.Descendants(element)
.Where(d => d.Attributes.Contains(attribute) && d.Attributes[attribute].Value.Contains(valuePortion));
return _nodes;
}
示例15: SetRequestFormInfo
private static NewThreadRequest SetRequestFormInfo(HtmlAgilityPack.HtmlNode root)
{
NewThreadRequest data = new NewThreadRequest();
var formNodes = root.Descendants("input").ToArray();
var formKeyNode = formNodes
.Where(node => node.GetAttributeValue("name", "").Equals(THREAD_FORMKEY_KEY))
.FirstOrDefault();
var formCookieNode = formNodes
.Where(node => node.GetAttributeValue("name", "").Equals(THREAD_FORMCOOKIE_KEY))
.FirstOrDefault();
try
{
data.FormKey = formKeyNode.GetAttributeValue("value", "");
data.FormCookie = formCookieNode.GetAttributeValue("value", "");
}
catch (Exception)
{
throw new InvalidOperationException("Could not parse newReply form data.");
}
return data;
}