本文整理汇总了C#中HtmlAgilityPack.HtmlNode.SelectNodes方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlNode.SelectNodes方法的具体用法?C# HtmlNode.SelectNodes怎么用?C# HtmlNode.SelectNodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlAgilityPack.HtmlNode
的用法示例。
在下文中一共展示了HtmlNode.SelectNodes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseNode
internal static List<ChannelItemInfo> ParseNode(HtmlNode node, bool abroadOnly)
{
var items = new List<ChannelItemInfo>();
if (node == null)
return items;
var playableArticles = node.SelectNodes(".//article[contains(@class, 'playJsInfo-Core') or contains(@class, 'slick_item')]");
if (playableArticles != null)
foreach (var article in playableArticles)
{
var playable = ParsePlayableArticle(article, abroadOnly);
if (playable != null)
items.Add(playable);
}
var folderArticles = node.SelectNodes(".//article[not(contains(@class, 'playJsInfo-Core') or contains(@class, 'slick_item'))]");
if (folderArticles != null)
foreach (var article in folderArticles)
{
var folder = ParseFolderArticle(article);
if (folder != null)
items.Add(folder);
}
return items;
}
示例2: ParseMovieListHtml
private List<Movie> ParseMovieListHtml(HtmlNode htmlNode, string xPath)
{
try
{
var movies = new List<Movie>();
var hnc = htmlNode.SelectNodes(xPath);
var hnc2 = htmlNode.SelectNodes("//div/a/img");
if (hnc.Count < 1)
return null;
for (int i = 0; i < hnc.Count; i++)
{
var node1 = hnc2[i];
var node = hnc[i];
var movie = new Movie();
var hac = node1.Attributes;
movie.Grade =node.SelectSingleNode("div[@class='fm-movie-desc']/div/span[@class='fm-rating']").InnerText.Replace("\n", "").RemoveSpace().Trim();
movie.Image = hac[0].Value.Replace("-poster100","").Trim();
movie.Name = node.SelectNodes("div[@class='fm-movie-desc']/div")[0].InnerText.Replace("\n","").RemoveSpace().Trim();
movie.Director =node.SelectNodes("div[@class='fm-movie-desc']/div")[2].InnerText.Replace("\n", "").RemoveSpace().Trim();
movie.Story = node.SelectNodes("div[@class='fm-movie-desc']/div")[3].InnerText.Replace("\n", "").RemoveSpace().Trim();
movie.Actor =node.SelectNodes("div[@class='fm-movie-desc']/div")[4].InnerText.Replace("\n","").RemoveSpace().Trim();
movie.DetailUrl = node.SelectSingleNode("div[@class='fm-movie-cover']/a").Attributes["href"].Value.Trim();
movies.Add(movie);
}
return movies;
}
catch (Exception e)
{
throw e;
}
}
示例3: YoutubeVideoEntry
public YoutubeVideoEntry(HtmlNode node)
{
var url_node = node.SelectNodes(".//a[@href]");
if (url_node != null)
{
var url_value = url_node.FirstOrDefault().Attributes["href"].Value;
var splitIndex = url_value.IndexOf("&");
if (splitIndex > 0)
{
url = "http://www.youtube.com" + url_value.Substring(0, splitIndex);
}
}
var title_node = node.SelectNodes(".//span[contains(@class, 'video-title')]");
if (title_node != null)
title = title_node.FirstOrDefault().InnerText;
if (!String.IsNullOrEmpty(title))
title = title.Trim();
var img_node = node.SelectNodes(".//img[@src]");
if (img_node != null)
imageUrl = "http:" + img_node.FirstOrDefault().Attributes["src"].Value;
}
示例4: retrieveTitle
protected override string retrieveTitle(HtmlNode node)
{
string title = node.SelectNodes("//div[contains(@class, 'entry-content')]//strong"
+ "|//div[contains(@class, 'entry-content')]//b")?.First()?.InnerText ?? "";
node.SelectNodes("//div[contains(@class, 'entry-content')]//strong"
+ "|//div[contains(@class, 'entry-content')]//b")?.First()?.Remove();
return title;
}
示例5: ParseResultSection
private EuroMillionsResult ParseResultSection(HtmlNode section)
{
var date = DateTime.ParseExact(section.SelectSingleNode(".//div[@class = 'floatLeft']/a").InnerText, "dd/MM/yyyy", CultureInfo.InvariantCulture);
var balls = section.SelectNodes(".//td[@class = 'euro-ball-s']").Select(x => Convert.ToInt32(x.InnerText));
var bonusBalls = section.SelectNodes(".//td[@class = 'euro-lucky-star-s']").Select(x => Convert.ToInt32(x.InnerText));
return new EuroMillionsResult(date, 0, balls.ToList(), bonusBalls.ToList());
}
示例6: run
/// <summary>
/// Run xpath from html or node
/// </summary>
private List<KeyValuePair<string, object>> run(HtmlNode node)
{
Factory.Instance.iInfo(string.Format("Running xpathSingle id : {0}", rule.id));
if (node == null)
return new List<KeyValuePair<string, object>>();
//Get all attriibutes by type and save to List<KeyValuePair<string, object>>
foreach (Db.xpathSingleAttributes attr in rule.attributes)
{
object val = null;
if (attr.getType == Db.xpathSingleAttributesGetType.nodeCollection)
val = node.SelectNodes(attr.xpath);
else if (attr.getType == Db.xpathSingleAttributesGetType.count)
{
HtmlNodeCollection c = node.SelectNodes(attr.xpath);
if (c != null)
val = c.Count.ToString();
}
else
{
string val2 = string.Empty;
HtmlNode n = node.SelectSingleNode(attr.xpath);
if (n != null)
{
if (attr.getType == Db.xpathSingleAttributesGetType.singleNode)
val = n;
else
{
if (attr.getType == Db.xpathSingleAttributesGetType.text)
val2 = n.InnerText.Trim();
if (attr.getType == Db.xpathSingleAttributesGetType.html)
val2 = n.InnerHtml.Trim();
if (attr.getType == Db.xpathSingleAttributesGetType.attribute)
{
if (n.Attributes[attr.attributeName] != null)
val2 = n.Attributes[attr.attributeName].Value;
}
val = postProcessResult(val2, attr);
if(attr.getType != Db.xpathSingleAttributesGetType.html && attr.getType != Db.xpathSingleAttributesGetType.nodeCollection &&
attr.getType != Db.xpathSingleAttributesGetType.singleNode)
Factory.Instance.iInfo(string.Format("{0} = {1}",attr.id,val));
}
}
}
res.Add(new KeyValuePair<string, object>(attr.id, val));
}
return res;
}
示例7: GetDishInfoList
public HtmlNodeCollection GetDishInfoList(HtmlNode dishTypeNode)
{
var baseCollectionSite = new BaseCollectionSite(PageUrl);
var dishNodeList = dishTypeNode.SelectNodes(DishesPath());
if (dishNodeList == null || dishNodeList.Count <= 0)
{
return new HtmlNodeCollection(null);
}
var scripNode = dishTypeNode.SelectSingleNode(@"./../../../../..//div[@class='rec-dishes tab-item active']/div[@class='pic-list J_toggle']/ul/script");
if (scripNode != null && !string.IsNullOrWhiteSpace(scripNode.InnerText))
{
var liNodeList = baseCollectionSite.BaseHtmlNodeCollection(scripNode.InnerText);
if (liNodeList != null)
{
var dishLiList = liNodeList.SelectNodes(".//li");
if (dishLiList != null)
{
foreach (var dishLi in dishLiList)
{
dishNodeList.Add(dishLi);
}
}
}
}
return dishNodeList;
}
示例8: SetValue
public bool SetValue(HtmlNode n, string value)
{
if (n is HtmlNode && n.Name == "select")
{
foreach (HtmlNode o in n.SelectNodes("option"))
{
o.SetAttributeValue("selected", o.GetAttributeValue("value", "").Equals(value) ? "selected" : "");
}
return true;
}
if (n is HtmlNode && n.Name == "input")
{
switch (n.GetAttributeValue("type", ""))
{
case "radio":
n.SetAttributeValue("checked", n.GetAttributeValue("value", "").Equals(value) ? "checked" : "");
break;
default:
n.SetAttributeValue("value", value);
break;
}
n.SetAttributeValue("value", value);
return true;
}
return false;
}
示例9: ParseRegionElement
private void ParseRegionElement(HtmlNode region)
{
var regionTitle = region.SelectSingleNode("h2").InnerText;
foreach (var server in region.SelectNodes(".//div[@class=\"server\" or @class=\"server alt\"]"))
{
var serverName = server.SelectSingleNode(".//div[@class=\"server-name\"]").InnerText.Trim();
var pollCategoryValue = new PollCategoryValue();
var possibleCategoryMatch = Categories.FirstOrDefault(p => string.Compare(p.Region, regionTitle, true) == 0 && string.Compare(p.ServerCategory, serverName) == 0);
if (possibleCategoryMatch == null)
continue;
pollCategoryValue.CategoryID = possibleCategoryMatch.PollCategoryID;
pollCategoryValue.Status = PollStatusType.Unknown;
pollCategoryValue.CreatedTime = DateTime.Now;
foreach (var div in server.SelectNodes("div"))
{
if (div.OuterHtml.Contains("status-icon"))
{
pollCategoryValue.Status = div.OuterHtml.Contains("status-icon up") ? PollStatusType.Up : PollStatusType.Down;
}
}
DB.InsertPollCategoryValue(pollCategoryValue);
}
}
示例10: GetOptions
public List<FormElement> GetOptions(HtmlNode htmlNode)
{
List<FormElement> options = new List<FormElement>();
HtmlNodeCollection nodeTags = htmlNode.SelectNodes(@".//option");
if (nodeTags != null)
{
foreach (HtmlNode node in nodeTags)
{
string id = node.GetAttributeValue("id", "");
string type = "option";
string name = node.GetAttributeValue("name", "");
string value = node.GetAttributeValue("value", "");
bool chk = node.Attributes["selected"] != null;
FormElement el = new FormElement();
el.Id = id;
el.Type = type;
el.Name = node.NextSibling.InnerText;
el.Value = value;
el.Type = type;
el.Checked = chk;
options.Add(el);
}
}
return options;
}
示例11: run
/// <summary>
/// Run xpath from html or node
/// </summary>
public List<List<KeyValuePair<string, object>>> run(HtmlNode node)
{
Factory.Instance.iInfo(string.Format("Running xpathCollection id : {0}", rule.id));
HtmlNodeCollection nodes = new HtmlNodeCollection(node);
HtmlNodeCollection n2 = node.SelectNodes(rule.xpath);
if (n2 != null)
{
foreach (HtmlNode n in n2)
nodes.Add(n);
}
//run
if (node != null)
{
foreach (HtmlNode n in nodes)
{
List<KeyValuePair<string, object>> last_val = null;
if (rule.xpathSingle != null)
{
XPathSingle xs = new XPathSingle(rule.xpathSingle, last_val);
last_val = (List<KeyValuePair<string, object>>)xs.Run(n);
res.Add(last_val);
}
}
}
return res;
}
示例12: MapHtmlRowToModel
private static Nhl_Players_Rtss_Skater MapHtmlRowToModel(HtmlNode row, NhlSeasonType nhlSeasonType, int year)
{
HtmlNodeCollection tdNodes = row.SelectNodes(@"./td");
Nhl_Players_Rtss_Skater model = new Nhl_Players_Rtss_Skater();
model.NhlSeasonType = nhlSeasonType;
model.Year = year;
model.Number = 0;
model.Name = tdNodes[1].InnerText;
model.Team = tdNodes[2].InnerText;
model.Position = tdNodes[3].InnerText;
model.GamesPlayed = ConvertStringToInt(tdNodes[4].InnerText);
model.Hits = ConvertStringToInt(tdNodes[5].InnerText);
model.BlockedShots = ConvertStringToInt(tdNodes[6].InnerText);
model.MissedShots = ConvertStringToInt(tdNodes[7].InnerText);
model.Giveaways = ConvertStringToInt(tdNodes[8].InnerText);
model.Takeaways = ConvertStringToInt(tdNodes[9].InnerText);
model.FaceoffsWon = ConvertStringToInt(tdNodes[10].InnerText);
model.FaceoffsLost = ConvertStringToInt(tdNodes[11].InnerText);
model.FaceoffsTaken = ConvertStringToInt(tdNodes[12].InnerText);
model.FaceoffWinPercentage = Convert.ToDouble(tdNodes[13].InnerText);
model.PercentageOfTeamFaceoffsTaken = Convert.ToDouble(tdNodes[14].InnerText);
model.Shots = ConvertStringToInt(tdNodes[15].InnerText);
model.Goals = ConvertStringToInt(tdNodes[16].InnerText);
model.ShootingPercentage = Convert.ToDouble(tdNodes[17].InnerText);
return model;
}
示例13: IdentifyMacros
/// <summary>
/// Identify Macros
/// </summary>
/// <param name="skeleton">skeleton</param>
/// <param name="pageType">page Type</param>
/// <returns></returns>
private void IdentifyMacros(HtmlNode skeleton, PageType pageType)
{
var menuProperties = new List<PropertyDTO>();
var doc = skeleton.OwnerDocument;
var propertyFactory = factory.PropertyFactory;
foreach (var menuNode in pageType.MacroXpaths
.SelectMany(xpath => skeleton.SelectNodes(xpath))
.Where(n => n != null && n.ParentNode != null))
{
var property = propertyFactory.GetNew();
menuProperties.Add(property);
var propertyNode = doc.CreateTextNode(property.TemplateReference);
menuNode.ParentNode.ReplaceChild(propertyNode, menuNode);
}
var macros = menuProperties.Select(p => new Definition
{
Number = p.Number,
Name = p.Name,
TemplateReference = p.TemplateReference,
IsMacro = true
});
pageType.Definitions.AddRange(macros);
}
示例14: MapHtmlRowToModel
private static Nhl_Players_Bio_Goalie MapHtmlRowToModel(HtmlNode row, NhlSeasonType nhlSeasonType, int year)
{
HtmlNodeCollection tdNodes = row.SelectNodes(@"./td");
Nhl_Players_Bio_Goalie model = new Nhl_Players_Bio_Goalie();
model.NhlSeasonType = nhlSeasonType;
model.Year = year;
model.Number = ConvertStringToInt(tdNodes[0].InnerText);
model.Name = tdNodes[1].InnerText;
model.Team = tdNodes[2].InnerText;
model.Position = "G";
model.DateOfBirth = Convert.ToDateTime(tdNodes[3].InnerText.Replace("'", "/"));
model.BirthCity = tdNodes[4].InnerText;
model.StateOrProvince = tdNodes[5].InnerText;
model.BirthCountry = tdNodes[6].InnerText;
model.HeightInches = ConvertStringToInt(tdNodes[7].InnerText);
model.WeightLbs = ConvertStringToInt(tdNodes[8].InnerText);
model.Catches = tdNodes[9].InnerText;
model.Rookie = tdNodes[10].InnerText;
model.DraftYear = ConvertStringToInt(tdNodes[11].InnerText);
model.DraftRound = ConvertStringToInt(tdNodes[12].InnerText);
model.DraftOverall = ConvertStringToInt(tdNodes[13].InnerText);
model.GamesPlayed = ConvertStringToInt(tdNodes[14].InnerText);
model.Wins = ConvertStringToInt(tdNodes[15].InnerText);
model.Losses = ConvertStringToInt(tdNodes[16].InnerText);
model.OTSOLosses = ConvertStringToInt(tdNodes[17].InnerText);
model.GAA = Convert.ToDouble(tdNodes[18].InnerText);
model.SavePercentage = Convert.ToDouble(tdNodes[19].InnerText);
model.Shutouts = ConvertStringToInt(tdNodes[20].InnerText);
return model;
}
示例15: ParseSubAchievements
private IList<Achievement> ParseSubAchievements(Achievement achievement, HtmlNode subAchievementNode)
{
IList<Achievement> subAchievements = new List<Achievement>();
HtmlNodeCollection achievements = subAchievementNode.SelectNodes("./li");
if (achievements != null)
{
foreach (HtmlNode subNode in achievements)
{
// TODO : Parse out achievement id
if ( subNode.Attributes["onmousemove"] != null )
{
Match match = parseTooltip.Match(subNode.Attributes["onmousemove"].Value);
if ( match.Success )
{
string subAchievementId = match.Groups["achievementid"].Value;
int blizzardId = 0;
int.TryParse(subAchievementId, out blizzardId);
Achievement subAchievement = _service.Find(blizzardId);
if (subAchievement == null)
{
subAchievement = new Achievement() { BlizzardID = blizzardId };
subAchievement.Name = GetValueAsString(subNode, ".//h3");
subAchievement.Description = GetValueAsString(subNode, ".//div[@class='color-tooltip-yellow']");
subAchievement.Points = GetValueAsInt32(subNode, ".//span[@class='points border-3']");
_service.Save(subAchievement);
}
achievement.Points = achievement.Points - subAchievement.Points;
subAchievements.Add(subAchievement);
}
}
}
}
return subAchievements;
}