本文整理汇总了C#中HtmlAgilityPack.HtmlNode类的典型用法代码示例。如果您正苦于以下问题:C# HtmlNode类的具体用法?C# HtmlNode怎么用?C# HtmlNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HtmlNode类属于HtmlAgilityPack命名空间,在下文中一共展示了HtmlNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertContentTo
private static void ConvertContentTo(HtmlNode node, TextWriter outText)
{
foreach (HtmlNode subnode in node.ChildNodes)
{
ConvertTo(subnode, outText);
}
}
示例2: SanitizerNodeVisited
void SanitizerNodeVisited(string nodeName, HtmlNode node, XmlWriter writer)
{
if (nodeName == "img" && node.Attributes["src"] != null && node.Attributes["src"].Value.StartsWith("cid:"))
{
// split src
var src = node.Attributes["src"].Value.Split(new[] { ':' }, 2);
if (src.Length == 2)
{
// Find inline attachment with given contentid
var document = source.Documents.FirstOrDefault(d => d.ContentType == ContentType.Inline && d.ContentId == src[1]);
if (document != null)
{
// Replace content-id url with filename
var filename = ClientState.Current.Storage.ResolvePhysicalFilename(".", document.StreamName);
node.Attributes["src"].Value = String.Format("file://{0}", filename);
}
}
}
else if (nodeName == "a" && node.Attributes["href"] != null)
{
var url = node.Attributes["href"].Value;
// Clean href and inject javascript hook
node.Attributes["href"].Value = String.Empty;
writer.WriteAttributeString("onclick", String.Format("javascript:window.external.JsNavigate('{0}')", url));
}
}
示例3: ParseResult
private Result ParseResult(HtmlNode resultSet)
{
string[] courseSplit = _currentCourse.Split(new[] { "<br>" }, StringSplitOptions.RemoveEmptyEntries);
string courseName = courseSplit[0];
string eventName = courseSplit[1];
var doc = new HtmlDocument();
doc.LoadHtml(resultSet.OuterHtml);
IEnumerable<HtmlNode> allResults = doc.DocumentNode.QuerySelectorAll("td");
string position = allResults.ElementAt(0).QuerySelector("b").InnerText;
string name = allResults.ElementAt(1).QuerySelector("b").InnerText;
string jockey = allResults.ElementAt(2).QuerySelector("b").InnerText;
string startingPrice = allResults.ElementAt(3).QuerySelector("b").InnerText.Trim();
var price = new Price{DecimalPrice = 0,Denominator=0,Numerator = 0};
try {
price = new Price(startingPrice);
} catch(ArgumentException) {}
return new Result
{
CourseName = courseName,
EventName = eventName,
Position = position,
HorseName = name,
JockeyName = jockey,
StartingPriceDecimal = price.DecimalPrice,
StartingPriceDenominator = price.Denominator,
StartingPriceNumerator = price.Numerator
};
}
示例4: 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);
}
}
示例5: NavigateToSubstitutionTableAndRemoveTextNodex
private HtmlNodeCollection NavigateToSubstitutionTableAndRemoveTextNodex (HtmlNode root)
{
HtmlNode vp = root.LastChild.PreviousSibling;
HtmlNode haupt = vp.ChildNodes[5];
HtmlNodeCollection collectionWithoutTextNodes = removeTextNodes(haupt.ChildNodes);
return collectionWithoutTextNodes;
}
示例6: ProcessContent
private static void ProcessContent(HtmlNode node, TextWriter outText)
{
foreach (var child in node.ChildNodes)
{
ProcessNode(child, outText);
}
}
示例7: TagOpenToken
public TagOpenToken(int id, HtmlNode node, TextVisualProperties properties, int parentID)
: base(id)
{
Name = node.Name;
TextProperties = properties;
ParentID = parentID;
}
示例8: OnScrape
protected override string OnScrape(string url, HtmlNode elem)
{
url = SubstringBetween(elem.InnerHtml, "un=\"", "\"");
if (!url.StartsWith("http"))
url = "http://" + url;
return new Uri(url).AbsoluteUri;
}
示例9: CreateSchedule_WFromNode
// Schedule_W 얻기
private Schedule_W CreateSchedule_WFromNode(HtmlNode node, Int32 year, Int32 month, Int32 day)
{
try
{
if (GetInnerHtml(node, "none") != null || GetInnerHtml(node, "relay") == null)
{
return null;
}
return new Schedule_W
{
Year = year,
Month = month,
Day = day,
Time = GetInnerHtml(node, "time"),
Play = GetInnerHtml(node, "play"),
Relay = GetInnerHtml(node, "relay"),
BallPark = GetInnerHtml(node, "ballpark"),
Etc = GetInnerHtml(node, "etc"),
};
}
catch (Exception exception)
{
throw exception;
}
}
示例10: BuildMarketRate
private MarketRateModel BuildMarketRate(HtmlNode monthNode)
{
var result = new MarketRateModel();
string value = "";
var dataCode = monthNode.GetAttributeValue("href", "http://finance.ifeng.com/app/hq/stock/sh000001/");
if ("http://finance.ifeng.com/app/hq/stock/sh000001/" == dataCode)
{
value = monthNode.NextSibling.NextSibling.InnerText.Trim();
value = value.Split(' ')[0];
result.Type = RateType.StockShangzheng;
result.Rate = decimal.Parse(value);
}
else if ("http://finance.ifeng.com/app/hq/stock/sz399001/" == dataCode)
{
value = monthNode.NextSibling.NextSibling.InnerText.Trim();
value = value.Split(' ')[0];
result.Type = RateType.StockShenzhen;
result.Rate = decimal.Parse(value);
}
else
{
return null;
}
result.CreateTime = DateTime.Now;
result.RateDay = DateTime.Now.Date;
result.Source = SourceType.eIfeng;
return result;
}
示例11: 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;
}
示例12: GetListNodeToTag
public static List<HtmlNode> GetListNodeToTag(HtmlNode node, string tag,string att, bool remove_text = false)
{
// for vao chirdNode
node = node.ChildNodes.Where(t => t.GetAttributeValue(tag, "") == att).ToList()[0];
//end
return GetListNode(node, remove_text);
}
示例13: Field
public Field(HtmlNode node)
{
String fieldInnerText = Utils.RemoveAllNotNumberCharacters(node.InnerText);
String[] tempArray = fieldInnerText.Split(',');
this.actual = int.Parse(tempArray[0]);
this.max = int.Parse(tempArray[1]);
}
示例14: GetTable1Node
private HtmlNode GetTable1Node(HtmlNode node)
{
HtmlNode table = UIUtils.CreateReportTableNode(node);
UIUtils.AddColumnRowToTable(table,
"Total Number of Patients",
highrisk.denominator.ToString("#,###,###"),"");
int percent = (int)Math.Round(100 * (double)high_risk_prevelance / (double)highrisk.denominator, 0);
UIUtils.AddColumnRowToTable(table,
"All High Risk BRCA Patients",
high_risk_incidence.ToString("#,###,###"),
percent.ToString() + "%");
percent = (int)Math.Round(100 * (double)high_risk_prevelance / (double)highrisk.denominator, 0);
UIUtils.AddColumnRowToTable(table,
"New High Risk BRCA",
high_risk_incidence.ToString("#,###,###"),
percent.ToString() + "%");
percent = (int)Math.Round(100 * (double)high_risk_seenInRC / (double)highrisk.denominator, 0);
UIUtils.AddColumnRowToTable(table,
"All High Risk BRCA Seen In Cancer Genetics",
high_risk_seenInRC.ToString("#,###,###"),
percent.ToString() + "%");
return table;
}
示例15: ExtractTitles
private static IEnumerable<string> ExtractTitles(HtmlNode container)
{
// <a href="http://fr.feedbooks.com/item/316137/les-les-de-l-espace" itemprop="url">Les Îles de l'espace</a>
return from element in container.Descendants("a")
where element.GetAttributeValue("href", "").StartsWith("http://fr.feedbooks.com/item/")
select element.InnerText;
}