本文整理汇总了C#中HtmlAgilityPack.HtmlDocument.QuerySelectorAll方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlDocument.QuerySelectorAll方法的具体用法?C# HtmlDocument.QuerySelectorAll怎么用?C# HtmlDocument.QuerySelectorAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlAgilityPack.HtmlDocument
的用法示例。
在下文中一共展示了HtmlDocument.QuerySelectorAll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public static ComicParseResult Parse(string html)
{
if (html == null) throw new ArgumentNullException(nameof(html));
if (html == "") throw new ArgumentException($"{nameof(html)} should contain some text", nameof(html));
var doc = new HtmlDocument();
doc.LoadHtml(html);
var img = doc.QuerySelectorAll("img.strip")
.FirstOrDefault(s => !s.Attributes.Contains("width"));
if (img == null)
return ComicParseResult.Fail("Could not find strip url");
var src = img.GetAttributeValue("src", null);
if (src == null)
return ComicParseResult.Fail("img element did not have src attribute");
var meta = doc.QuerySelector("meta[name='twitter:url']");
if (meta == null)
return ComicParseResult.Fail("Could not load twitter:url attribtue");
var content = meta.GetAttributeValue("content", null);
if (content == null)
return ComicParseResult.Fail("meta tag did not have content attribute");
var dateString = content.Replace("http://www.gocomics.com/pearlsbeforeswine/", "");
var date = DateTime.ParseExact(dateString, "yyyy/MM/dd", CultureInfo.InvariantCulture);
var uri = new Uri(src);
return ComicParseResult.Succeed(uri, date);
}
示例2: GetAcquiredFromUrl
public string GetAcquiredFromUrl(HtmlDocument doc)
{
try
{
var nodes = doc.QuerySelectorAll("div.padding-listItem > h2.heading--lg");
foreach (var node in nodes)
{
if (node.InnerText.Contains("Acquired From"))
{
var thenode = node.NextSibling.NextSibling;
if (thenode.Attributes["href"] != null)
{
return thenode.Attributes["href"].Value;
}
}
}
return "";
}
catch (Exception e)
{
_logger.ErrorFormat("Error getting Acquired from", e);
return "";
}
}
示例3: GetFlavors
public List<string> GetFlavors(HtmlDocument doc)
{
try
{
var nodes = doc.QuerySelectorAll("div.divider .bottom > h2.heading--lg");
var flavors = new List<string>();
foreach (var node in nodes)
{
if (node.InnerText.Contains("Flavor Profile"))
{
var formnode = node.NextSibling.NextSibling;
foreach (var innernode in formnode.ChildNodes)
{
if (innernode.NodeType == HtmlNodeType.Element)
{
flavors.Add(innernode.InnerText);
}
}
}
}
return flavors;
}
catch (Exception e)
{
_logger.Error("Get Flavors", e);
return null;
}
}