本文整理汇总了C#中HtmlAgilityPack.HtmlNode.SelectSingleNode方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlNode.SelectSingleNode方法的具体用法?C# HtmlNode.SelectSingleNode怎么用?C# HtmlNode.SelectSingleNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlAgilityPack.HtmlNode
的用法示例。
在下文中一共展示了HtmlNode.SelectSingleNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddPackage
private static void AddPackage(SteamApp app, HtmlNode packageNode)
{
var package = app.AddNewPackage();
var packageTitleNode = packageNode.SelectSingleNode($"//{PackageTitle}");
package.Title = packageTitleNode.InnerHtml.Replace("Buy ", "").Trim();
var priceNodes = packageNode.SelectNodes($"//div[@class='{PackagePriceXPath}']");
if (priceNodes != null)
{
var priceNode = priceNodes[0];
package.CurrentPrice = ParseNodeWithCurrencyToDecimal(priceNode);
package.OriginalPrice = package.CurrentPrice;
}
else
{
var originalPriceNode = packageNode.SelectSingleNode($"//div[@class='{PackageOriginalPriceXPath}']");
package.OriginalPrice = ParseNodeWithCurrencyToDecimal(originalPriceNode);
var discountPriceNode = packageNode.SelectSingleNode($"//div[@class='{PackageDiscountPriceXPath}']");
package.CurrentPrice = ParseNodeWithCurrencyToDecimal(discountPriceNode);
}
}
示例2: GetSegment
public Segment GetSegment(HtmlNode segmentDiv, string day)
{
var imgDiv = segmentDiv.SelectSingleNode("./div[@class='programListContentImgArea']");
var txtDiv = segmentDiv.SelectSingleNode("./div[@class='programListContentTextArea scheduleColumnTextArea']");
var anchor = txtDiv.GetChildById("hypProgramTxt");
var authorNode = txtDiv.GetChildById("lblAuthor");
var imageNode = imgDiv.SelectSingleNode(".//img");
//TODO: Move url building (below) into UrlBuilder class
var segment = new Segment
{
DayDescription = day,
Title = anchor.DecodeHtml(),
SegmentDetailUrl = configurationManager.BookTvDomain + anchor.GetAttributeValue("href", ""),
Time = txtDiv.GetChildById("lblAirTime").DecodeHtml(),
Duration = txtDiv.GetChildById("lblLength").DecodeHtml(),
Author = (authorNode == null) ? "" : authorNode.DecodeHtml(),
ImageUrl = configurationManager.BookTvDomain + imageNode.Attributes["src"].Value,
};
segment.DurationInMinutes = durationParser.GetDurationInMinutes(segment.Duration);
segment.Date = dayParser.Parse(segment.DayDescription);
return segment;
}
示例3: Trade
public Trade(HtmlNode code)
{
htmlCode = code;
// fetch the trade ID (well, actually its the url)
id = htmlCode.SelectSingleNode("//a[contains(@href,'/trade/')]").GetAttributeValue("href", "");
// fetch the name, donator type is used to find it
HtmlNode node = htmlCode.SelectSingleNode("//span[@class='regular' or starts-with(@class, 'donator')]");
name = (node != null) ? node.InnerText : null;
// the trade's description
HtmlNode descriptionNode = htmlCode.SelectSingleNode("//div[@class='notes expandable show']");
description = (descriptionNode != null) ? descriptionNode.InnerText : "";
/*
* here we construct the item objects
*
*/
HtmlNode itemOfferBundleHtml = htmlCode.SelectSingleNode("(div[@class='four-column'])[1]");
HtmlNode itemRequestBundleHtml = htmlCode.SelectSingleNode("(div[@class='four-column'])[2]");
HtmlNodeCollection itemOfferHtml = itemOfferBundleHtml.SelectNodes("div[starts-with(@class, 'item')]");
HtmlNodeCollection itemRequestHtml = itemRequestBundleHtml.SelectNodes("div[starts-with(@class, 'item')]");
offer = new List<Item>();
request = new List<Item>();
for (int i = 0; i < itemOfferHtml.Count; i++) { offer.Add(new Item(itemOfferHtml[i])); }
for (int i = 0; i < itemRequestHtml.Count; i++) { request.Add(new Item(itemRequestHtml[i])); }
}
示例4: BuildProductBasicData
private ProductBasicData BuildProductBasicData(HtmlNode productNode)
{
log.DebugFormat("[BuildProductBasicData] OuterHtml= {0}.", productNode.OuterHtml);
//throw new NotImplementedException();
ProductBasicData returnValue = new ProductBasicData();
//should be transfered to barcode, but last digitals of the barcode is productId
returnValue.Barcode = productNode.Attributes.First(c => c.OriginalName == "DdPiD").Value;
returnValue.ProductId = productNode.Attributes.First(c => c.OriginalName == "DdPiD").Value;
returnValue.pbcatid = productNode.Attributes.First(c => c.OriginalName == "pbcatid").Value;
returnValue.qty = productNode.Attributes.First(c => c.OriginalName == "qty").Value;
returnValue.iq = productNode.Attributes.First(c => c.OriginalName == "iq").Value;
returnValue.inb = productNode.Attributes.First(c => c.OriginalName == "inb").Value;
//returnValue.ImageSource = productNode.SelectSingleNode("//img[@src]").Attributes.FirstOrDefault(c=> c.Name == "src").Value;
returnValue.ImageSource = productNode.SelectNodes("child::*/child::div/child::img").First().Attributes.First(c => c.Name == "src").Value;
returnValue.EffectivePrice = productNode.SelectSingleNode("child::*/child::div/child::div/child::div/child::span").InnerText;
//returnValue.EffectivePrice = productNode.SelectSingleNode("//span[@id='spnEffectivePrice']").InnerText;
//returnValue.Description = HttpUtility.HtmlDecode(productNode.SelectSingleNode("//div[@class='ProdBoxSupplierText']").InnerText);
returnValue.Description = HttpUtility.HtmlDecode(productNode.SelectSingleNode("child::*/child::div/child::div/child::a").InnerText);
returnValue.ProductName = HttpUtility.HtmlDecode(productNode.SelectSingleNode("child::*/child::div/child::div/child::a").InnerText);
log.DebugFormat("[BuildProductBasicData] fetched product={0}.", returnValue.ToString());
return returnValue;
}
示例5: MapHtmlNodeToMatch
internal Match MapHtmlNodeToMatch(HtmlNode root, MatchPath matchPath, int currentCount)
{
Match match = new Match();
match.Id = HtmlEntity.DeEntitize(root.SelectSingleNode(mainController.CombinePathWithListCount(matchPath.Id, currentCount)).Attributes[matchPath.IdAttribute].Value).Replace(matchPath.IdReplace, "");
HtmlNode heroNode = root.SelectSingleNode(mainController.CombinePathWithListCount(matchPath.Hero, currentCount));
if (heroNode != null)
{
string heroReference = root.SelectSingleNode(mainController.CombinePathWithListCount(matchPath.Hero, currentCount)).Attributes[HtmlAttributes.Hero.Attribute.Value].Value.Replace(HtmlAttributes.Hero.Replace.Value, "");
match.Hero = mainController.HeroController.GetHero(heroReference);
}
match.Result = mainController.MapStringToEnum<Results>(root.SelectSingleNode(mainController.CombinePathWithListCount(matchPath.Result, currentCount)).InnerText);
match.TimeAgo = DateTime.Parse(root.SelectSingleNode(mainController.CombinePathWithListCount(matchPath.TimeAgo, currentCount)).Attributes[MainController.HTML_ATTRIBUTE_DATETIME].Value);
match.Type = mainController.MapStringToEnum<Types>(root.SelectSingleNode(mainController.CombinePathWithListCount(matchPath.Type, currentCount)).InnerText);
match.Mode = mainController.MapStringToEnum<Modes>(root.SelectSingleNode(mainController.CombinePathWithListCount(matchPath.Mode, currentCount)).InnerText);
HtmlNode skillBracketNode = root.SelectSingleNode(mainController.CombinePathWithListCount(matchPath.Skillbracket, currentCount));
if (skillBracketNode != null)
match.Skillbracket = mainController.MapStringToEnum<Skillbrackets>(HtmlEntity.DeEntitize(skillBracketNode.InnerText));
match.Duration = mainController.ConvertStringToTimeSpan(root.SelectSingleNode(mainController.CombinePathWithListCount(matchPath.Duration, currentCount)).InnerText);
match.Kda = mainController.ConvertStringToKda(root.SelectSingleNode(mainController.CombinePathWithListCount(matchPath.Kda, currentCount)).InnerText);
return match;
}
示例6: VariableNameResolver
private string VariableNameResolver(HtmlNode row)
{
var isOptional = row.SelectSingleNode(@".//td[contains(@class,'description')]/span[@class='optional']");
var variable = row.SelectSingleNode(@".//td[@class=""name"" ]").InnerText + (isOptional != null ? "?" : "");
return variable;
}
示例7: getMoney
private static string getMoney(HtmlNode node)
{
try
{
string money = "";
string gold = HtmlEntity.DeEntitize(node.SelectSingleNode("descendant::span[@class='mgold']").InnerText).TrimStart();
string silver = HtmlEntity.DeEntitize(node.SelectSingleNode("descendant::span[@class='msilver']").InnerText).TrimStart();
string bronze = HtmlEntity.DeEntitize(node.SelectSingleNode("descendant::span[@class='mbronze']").InnerText).TrimStart();
if (gold != "")
money += gold;
if (silver != "")
if (silver.Length > 1)
money += silver;
else
if (gold == "")
money += silver;
else
money += '0' + silver;
if (bronze.Length > 1)
money += bronze;
else
money += '0' + bronze;
return money;
}
catch (NullReferenceException e)
{
return "";
}
}
示例8: ParseArticleInfoDiv
private static ArticleInfo ParseArticleInfoDiv(HtmlNode articleDiv)
{
var linkToArticle = articleDiv.SelectSingleNode("h3/a");
var dateDiv = articleDiv.SelectSingleNode("div[@class='headline-date']");
var commentCountNode = articleDiv.SelectSingleNode("h3/a[@class='commentCount']");
var articleInfo = new ArticleInfo();
articleInfo.Url = linkToArticle.Attributes["href"].Value;
if (articleInfo.Url.Contains(@"/video/"))
{
throw new CommonParsingException("Delfi TV article");
}
articleInfo.Id.ExternalId = articleInfo.Url.GetQueryParameterValueFromUrl("id");
articleInfo.Title = linkToArticle.InnerText;
articleInfo.DatePublished = DelfiWordyDateParser.Parse(dateDiv.InnerText);
articleInfo.DateScraped = DateTime.UtcNow.AddHours(2);
articleInfo.Id.Portal = Portal.Delfi;
articleInfo.CommentCount = commentCountNode == null ? 0 : Convert.ToInt32(commentCountNode.InnerText.TrimStart('(').TrimEnd(')'));
var articleId = Convert.ToInt32(articleInfo.Url.GetQueryParameterValueFromUrl("id"));
if (articleId == 0) throw new CommonParsingException("Article id not found");
return articleInfo;
}
示例9: MapHtmlNode
internal Stat MapHtmlNode(HtmlNode root, int currentCount)
{
string matchesPlayed = root.SelectSingleNode(string.Format(PlayerPath.MostPlayedHeroes.MatchesPlayed.Value, currentCount)).InnerText;
string winRate = root.SelectSingleNode(string.Format(PlayerPath.MostPlayedHeroes.Winrate.Value, currentCount)).InnerText;
string kdaRatio = root.SelectSingleNode(string.Format(PlayerPath.MostPlayedHeroes.Kda.Value, currentCount)).InnerText;
return new Stat(matchesPlayed.Replace(",", ""), winRate, kdaRatio.Replace(".", ","));
}
示例10: VariableTypeResolver
private string VariableTypeResolver(HtmlNode row)
{
var tdType = row.SelectSingleNode(@".//td[@class=""type"" ]");
//EntityCollection contains(entity) as no type information.
var typeNodes = tdType.SelectNodes(@".//span[@class='param-type']");
if (typeNodes == null)
return "any";
var types = typeNodes.Select(Program.TypeReader).ToArray().Distinct();
if (!types.Skip(1).Any() && types.First() == "Object")
{
var props = GetSignatureTypes(row.SelectSingleNode(@".//td[contains(@class,'description')]"));
if (props.Keys.Any())
{
// var type = "opt_" + Program.CalculateMD5Hash(string.Join("", props.Keys.OrderBy(k => k)));
var type = this._name + "Options";
var dependencies = new List<string>();
var writer = Program.GetWriter(type,_source);
if (writer != null)
{
props = props.ToDictionary(k => k.Key, v => Program.extractDependencies(dependencies, v.Value));
Program.WriteDependencies(type, dependencies, writer, null, null, _source);
writer.WriteLine($"interface {type}");
writer.WriteLine("{");
foreach (var prop in props)
{
writer.WriteLine($"\t{prop.Key}: {prop.Value};");
}
writer.WriteLine("}");
writer.WriteLine($"export = {type}");
}
return "Cesium." + type;
}
}
return string.Join("|", types);
}
示例11: ParseRemark
public static Remark ParseRemark(HtmlNode remarkNode)
{
var remark = new Remark();
//发现物
var discoveryNode = remarkNode.SelectSingleNode("a[@title!='']");
if (discoveryNode!=null)
{
var levelNode = discoveryNode.PreviousSibling.PreviousSibling;
var typeNode = levelNode.PreviousSibling.PreviousSibling;
remark.DiscoveryType = Enum.Parse(typeof(DisType), typeRegex.Match(typeNode.Attributes["src"].Value).Groups["type"].Value).ToString();
remark.DiscoveryLevel = Int32.Parse(levelNode.InnerText.Substring(0, 1));
remark.DiscoveryExp = Int32.Parse(discoveryNode.Attributes["title"].Value.Remove(0,5));
remark.Discovery = discoveryNode.InnerText;
}
//奖励物
var awardNode = remarkNode.SelectSingleNode("span[@style='color:#804000;']");
if (awardNode != null)
remark.AwardItem = awardNode.InnerText;
//相关任务
var relativeNodes = remarkNode.SelectNodes("descendant::a[@style='color:#C000C0;' or @style='color:DarkBlue;']");
if (relativeNodes != null)
{
foreach (HtmlNode relativeNode in relativeNodes)
{
IList<int> questList = null;
IList<string> foundNameList = null;
if (relativeNode.InnerText.StartsWith("前:"))
{
foundNameList = remark.PreFoundName;
questList = remark.PreQuestID;
}
else
{
questList = remark.FollowQuestID;
}
var match = questRegex.Match(relativeNode.Attributes["href"].Value);
if (relativeNode.InnerText.StartsWith("前:港口-") == false)
questList.Add(Int32.Parse(match.Groups["id"].Value));
else
foundNameList.Add(relativeNode.InnerText.Replace("前:港口-",""));
}
}
//接受城市
//last br next a
var cityNodes = remarkNode.SelectNodes("descendant::a[@class='MisCity']");
if (cityNodes != null)
{
cityNodes.All(node =>
{
if (node.InnerText == "南美开拓港" || node.InnerText == "东南亚开拓港" ||
node.InnerText == "掠夺地图" || node.InnerText == "沉船资讯")
return true;
remark.FromCityList.Add(node.InnerText);
return true;
});
}
return remark;
}
示例12: ExtractSnippet
protected override string ExtractSnippet(HtmlNode node)
{
if (node.SelectSingleNode("div/div[2]") != null)
{
return node.SelectSingleNode("div/div[2]").InnerText;
}
return string.Empty;
}
示例13: ExtractAuthor
protected override string ExtractAuthor(HtmlNode node)
{
if (node.SelectSingleNode("div/div[2]/div/div/span") != null)
{
return node.SelectSingleNode("div/div[2]/div/div/span").InnerText.Split('-')[0].Trim();
}
return string.Empty;
}
示例14: getDescription
private string getDescription(HtmlNode node)
{
var node2 = node.SelectSingleNode(".//div[@class='hoverbox-details']/p");
if (node2 == null)
node2 = node.SelectSingleNode(".//div[@class='list-item-main1']");//klipit
if (node2 != null)
return node2.InnerText;
return String.Empty;
}
示例15: ExtractTitle
protected override string ExtractTitle(HtmlNode node)
{
if (node.SelectSingleNode("div/div[1]/h3/a") != null)
{
return node.SelectSingleNode("div/div[1]/h3/a").InnerText;
}
return string.Empty;
}