本文整理汇总了C#中HtmlAgilityPack.HtmlDocument.GetText方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlDocument.GetText方法的具体用法?C# HtmlDocument.GetText怎么用?C# HtmlDocument.GetText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlAgilityPack.HtmlDocument
的用法示例。
在下文中一共展示了HtmlDocument.GetText方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTitle
public string GetTitle(HtmlDocument document)
{
return document.GetText("/html/head/title");
}
示例2: GetDescription
public string GetDescription(HtmlDocument document)
{
return document.GetText("/html/head/meta[@name='Description']");
}
示例3: GetDescription
public string GetDescription(HtmlDocument document)
{
return document.GetText("/html/body//*/div[@id='bodyContent']/div[@id='mw-content-text']/p");
}
示例4: FetchAndParseMetadata
public static Metadata FetchAndParseMetadata(string rqurl)
{
var content = FetchMetadata(rqurl).Result;
if(!string.IsNullOrWhiteSpace(content))
{
var html = new HtmlDocument();
html.LoadHtml(content);
var data = new Metadata {
Title = HttpUtility.HtmlDecode(html.DocumentNode.SelectSingleNode("//title")?.InnerText)
};
var titleTags = new List<string> {
"//meta[@property='og:title']",
"//meta[@property='twitter:title']"
};
var descriptionTags = new List<string> {
"//meta[@name='description']",
"//meta[@property='og:description']",
"//meta[@property='twitter:description']"
};
var imageTags = new List<string> {
"//meta[@property='og:image']",
"//meta[@property='twitter:image']"
};
var urlTags = new List<string> {
"//meta[@property='og:url']",
"//meta[@property='twitter:url']"
};
titleTags.ForEach(xpath => {
var title = html.GetText(xpath);
if(!string.IsNullOrWhiteSpace(title))
data.Title = HttpUtility.HtmlDecode(title);
});
// descriptionTags.ForEach(xpath => {
// var description = html.GetText(xpath);
// if(!string.IsNullOrWhiteSpace(description))
// data.Description = description;
// });
// imageTags.ForEach(xpath => {
// var image = html.GetText(xpath);
// if(!string.IsNullOrWhiteSpace(image))
// data.Image = image;
// });
// urlTags.ForEach(xpath => {
// var url = html.GetText(xpath);
// if(!string.IsNullOrWhiteSpace(url))
// data.Url = url;
// });
return data;
}
return null;
}