本文整理汇总了C#中IElement.QuerySelector方法的典型用法代码示例。如果您正苦于以下问题:C# IElement.QuerySelector方法的具体用法?C# IElement.QuerySelector怎么用?C# IElement.QuerySelector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IElement
的用法示例。
在下文中一共展示了IElement.QuerySelector方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseGeneralInformation
/// <summary>
/// Parses the specified post element and parses the general information about the post.
/// </summary>
/// <param name="postElement">The post element, which is to be parsed.</param>
internal override void ParseGeneralInformation(IElement postElement)
{
// Calls the base implementation
base.ParseGeneralInformation(postElement);
// Parses the content of the video post
IElement contentElement = postElement.QuerySelector("video");
this.Content = contentElement.GetElementsByTagName("source").Select(child => new Content
{
Uri = new Uri(child.GetAttribute("src"), UriKind.Absolute),
Kind = child.GetAttribute("type").ToUpperInvariant() == "VIDEO/MP4" ? ContentKind.Mp4 : ContentKind.WebM
}).ToList();
// Parses and retrieves the thumbnail of the video post
this.ThumbnailUri = new Uri(contentElement.GetAttribute("poster"), UriKind.Absolute);
}
示例2: ParseGeneralInformation
/// <summary>
/// Parses the specified post element and parses the general information about the post.
/// </summary>
/// <param name="postElement">The post element, which is to be parsed.</param>
internal override void ParseGeneralInformation(IElement postElement)
{
// Calls the base implementation
base.ParseGeneralInformation(postElement);
// Parses the content of the image post
IElement contentElement = postElement.QuerySelector("img");
this.Content = new List<Content>
{
new Content
{
Uri = new Uri(contentElement.GetAttribute("src"), UriKind.Absolute),
Kind = ContentKind.Jpeg
}
};
// Checks if the image post is a long post
this.IsLongPost = contentElement.GetAttribute("src").ToUpperInvariant().Contains("LONG-POST");
}
示例3: ParseGeneralInformation
/// <summary>
/// Parses the specified post element and parses the general information about the post.
/// </summary>
/// <param name="postElement">The post element, which is to be parsed.</param>
internal virtual void ParseGeneralInformation(IElement postElement)
{
// Parses the ID and the title of the post
this.Id = postElement.GetAttribute("data-entry-id");
this.Title = postElement.QuerySelector("header").TextContent.Trim();
// Checks if the post is a NSFW post
this.IsNotSafeForWork = postElement.QuerySelector(".nsfw-post") != null;
// Parses the number of comments and the number of upvotes of the post
int numberOfComments, numberOfUpVotes;
int.TryParse(postElement.GetAttribute("data-entry-comments").Trim(), out numberOfComments);
int.TryParse(postElement.GetAttribute("data-entry-votes").Trim(), out numberOfUpVotes);
this.NumberOfComments = numberOfComments;
this.NumberOfUpVotes = numberOfUpVotes;
}
示例4: CreateEntry
static IHtmlListItemElement CreateEntry(IDocument document, IElement header)
{
// Create a new li element
var item = document.CreateElement<IHtmlListItemElement>();
// Initially the text of the li is the same as the h* text
item.TextContent = header.TextContent;
// Get a potential (named) anchor here
var anchor = header.QuerySelector<IHtmlAnchorElement>("a");
// If there really is an anchor
if (anchor != null)
{
// Get the value of the name attribute
var name = anchor.GetAttribute("name");
// If the attribute exists (!= null) and makes sense (not empty)
if (!String.IsNullOrEmpty(name))
{
// Create a new anchor element
anchor = document.CreateElement<IHtmlAnchorElement>();
// Set its url to the anchor
anchor.Href = "#" + name;
// Set the anchor's text content to the header (= item) text
anchor.TextContent = item.TextContent;
// Replace the text node (= item content) with the anchor
item.ReplaceChild(anchor, item.FirstChild);
}
}
return item;
}
示例5: GetReleaseInfo
private ReleaseInfo GetReleaseInfo(IElement row, IElement downloadAnchor, string title, int category)
{
// Parse required data
var downloadAnchorHref = downloadAnchor.Attributes["href"].Value;
var torrentId = downloadAnchorHref.Substring(downloadAnchorHref.LastIndexOf('=') + 1);
var qFiles = row.QuerySelector("td:nth-last-child(6)");
var files = ParseUtil.CoerceLong(qFiles.TextContent);
var publishDate = DateTime.ParseExact(row.QuerySelector(".time.tooltip").Attributes["title"].Value, "MMM dd yyyy, HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime();
var torrentData = row.QuerySelectorAll(".number_column"); // Size (xx.xx GB[ (Max)]) Snatches (xx) Seeders (xx) Leechers (xx)
if (torrentData.Length != 4)
throw new Exception($"We expected 4 torrent datas, instead we have {torrentData.Length}.");
if (torrentId.Contains('#'))
torrentId = torrentId.Split('#')[0];
var size = ReleaseInfo.GetBytes(torrentData[0].TextContent);
var grabs = int.Parse(torrentData[1].TextContent);
var seeders = int.Parse(torrentData[2].TextContent);
var guid = new Uri(GuidUrl + torrentId);
// Build releaseinfo
return new ReleaseInfo
{
Title = title,
Description = title,
Category = category, // Who seasons movies right
Link = new Uri(DownloadUrl + torrentId),
PublishDate = publishDate,
Seeders = seeders,
Peers = seeders,
Files = files,
Size = size,
Grabs = grabs,
Guid = guid,
Comments = guid,
DownloadVolumeFactor = 0, // ratioless tracker
UploadVolumeFactor = 1
};
}
示例6: Map
private static WebElement Map(IElement node)
{
if (node == null)
return null;
var el = new WebElement(value => node.SetAttribute("value", value))
{
Attributes = node.Attributes.ToDictionary(x => x.Name, y => y.Value),
TagName = node.TagName,
Text = node.TextContent,
InnerHtml = node.InnerHtml,
OuterHtml = node.OuterHtml
};
el.OnQuerySelector(query => Map(node.QuerySelector(query)));
el.OnQuerySelectorAll(query => node.QuerySelectorAll(query).Select(Map));
return el;
}
示例7: QuerySelector
protected IElement QuerySelector(IElement Element, string Selector)
{
// AngleSharp doesn't support the :root pseudo selector, so we check for it manually
if (Selector.StartsWith(":root"))
{
Selector = Selector.Substring(5);
while (Element.ParentElement != null)
{
Element = Element.ParentElement;
}
}
return Element.QuerySelector(Selector);
}