本文整理汇总了C#中HtmlAgilityPack.HtmlNode.GetAttributeValue方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlNode.GetAttributeValue方法的具体用法?C# HtmlNode.GetAttributeValue怎么用?C# HtmlNode.GetAttributeValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlAgilityPack.HtmlNode
的用法示例。
在下文中一共展示了HtmlNode.GetAttributeValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitAsync
public async Task<HtmlNode> VisitAsync(VisitingContext context, HtmlNode node)
{
// We're only interested in stylesheets.
if (node.GetAttributeValue("rel", null) != "stylesheet")
return node;
var href = node.GetAttributeValue("href", null);
if (href == null)
return node;
var hrefUri = new Uri(href, UriKind.RelativeOrAbsolute);
if (!hrefUri.IsAbsoluteUri)
{
hrefUri = new Uri(context.Address, hrefUri);
}
// Get the stylesheet and insert it inline.
var content = default(string);
try
{
content = await context.WebClient.DownloadAsync(hrefUri);
}
catch (WebException)
{
return node;
}
content = "<style>" + content + "</style>";
return HtmlNode.CreateNode(content);
}
示例2: Form
/// <summary>
///
/// </summary>
/// <param name="formNode"></param>
/// <param name="session"></param>
/// <param name="baseUrl"></param>
/// <param name="charset">The character set used in the previoius response (from which the form originates).</param>
public Form(HtmlNode formNode, ISession session, Uri baseUrl, string charset)
{
Condition.Requires(formNode, "formNode").IsNotNull();
Condition.Requires(session, "session").IsNotNull();
Condition.Requires(baseUrl, "baseUrl").IsNotNull();
if (!formNode.Name.Equals("form", StringComparison.OrdinalIgnoreCase))
throw new ArgumentException(string.Format("Cannot create HTML form from '{0}' node.", formNode.Name));
Action = new Uri(baseUrl, formNode.GetAttributeValue("action", ""));
Method = formNode.GetAttributeValue("method", "get");
Session = session;
BaseUrl = baseUrl;
ResponseCharset = charset;
string enctype = formNode.GetAttributeValue("enctype", null);
EncodingType = (enctype != null ? new MediaType(enctype) : MediaType.ApplicationFormUrlEncoded);
AcceptCharset = formNode.GetAttributeValue("accept-charset", null);
Values = new Hashtable();
SubmitElements = new List<SubmitElement>();
ParseInputs(formNode);
}
示例3: SetValue
public bool SetValue(HtmlNode n, string value)
{
if (n is HtmlNode && n.Name == "select")
{
foreach (HtmlNode o in n.SelectNodes("option"))
{
o.SetAttributeValue("selected", o.GetAttributeValue("value", "").Equals(value) ? "selected" : "");
}
return true;
}
if (n is HtmlNode && n.Name == "input")
{
switch (n.GetAttributeValue("type", ""))
{
case "radio":
n.SetAttributeValue("checked", n.GetAttributeValue("value", "").Equals(value) ? "checked" : "");
break;
default:
n.SetAttributeValue("value", value);
break;
}
n.SetAttributeValue("value", value);
return true;
}
return false;
}
示例4: GetPageNumber
private static int GetPageNumber(HtmlNode threadNode)
{
if (threadNode != null && !string.IsNullOrEmpty(threadNode.GetAttributeValue("value", string.Empty)))
{
return Convert.ToInt32(threadNode.GetAttributeValue("value", string.Empty));
}
return 1;
}
示例5: Convert
public override string Convert(HtmlNode node)
{
string alt = node.GetAttributeValue("alt", string.Empty);
string src = node.GetAttributeValue("src", string.Empty);
string title = this.ExtractTitle(node);
title = title.Length > 0 ? string.Format(" \"{0}\"", title) : "";
return string.Format("![{0}]({1}{2})", alt, src, title);
}
示例6: Parse
public static Note Parse(HtmlNode Node)
{
string Grade = Node.InnerText.Trim();
string Name = Node.GetAttributeValue("title", "Névtelen jegy");
string Href = Node.GetAttributeValue("href", "");
Match Match = Regex.Match(Href, "jegyId=(?<id>[0-9]+)", RegexOptions.IgnoreCase);
int ID = int.Parse(Match.Groups["id"].Value);
string T = Node.GetAttributeValue("class", "jegy2");
NoteType Type = (NoteType)(int.Parse(T.Substring(T.Length - 1, 1)));
return new Note(ID, Grade, Name, Type);
}
示例7: GetTargetFromFilter
public static string GetTargetFromFilter(HtmlNode node, IFilter filter)
{
switch (filter.GetNodeType())
{
case NodeType.Image:
return node.GetAttributeValue("src", "");
case NodeType.Link:
return node.GetAttributeValue("href", "");
default:
return "";
}
}
示例8: AnalyseAnchor
static AnchorAnalysis AnalyseAnchor(HtmlNode anchor)
{
var href = anchor.GetAttributeValue("href", null);
var rel = anchor.GetAttributeValue("rel", null);
var title = anchor.GetAttributeValue("title", null);
var text = anchor.InnerText;
// todo: determine if its an offsite link?
// determine if it contains a title, has text - if not, image? adivse
return new AnchorAnalysis(text, title, href, rel, new Message[0]);
}
示例9: Parse
/// <summary>
/// Parses a forum post in a thread.
/// </summary>
/// <param name="postNode">The post HTML node.</param>
public void Parse(HtmlNode postNode)
{
User = ForumUserEntity.FromPost(postNode);
HtmlNode postDateNode =
postNode.Descendants()
.FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Equals("postdate"));
string postDateString = postDateNode == null ? string.Empty : postDateNode.InnerText;
if (postDateString != null)
{
PostDate = postDateString.WithoutNewLines().Trim();
}
PostIndex = ParseInt(postNode.GetAttributeValue("data-idx", string.Empty));
var postId = postNode.GetAttributeValue("id", string.Empty);
if (!string.IsNullOrEmpty(postId) && postId.Contains("#"))
{
PostId =
Int64.Parse(postNode.GetAttributeValue("id", string.Empty)
.Replace("post", string.Empty)
.Replace("#", string.Empty));
}
else if (!string.IsNullOrEmpty(postId) && postId.Contains("post"))
{
PostId =
Int64.Parse(postNode.GetAttributeValue("id", string.Empty)
.Replace("post", string.Empty));
}
else
{
PostId = 0;
}
var postBodyNode = postNode.Descendants("td")
.FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Equals("postbody"));
this.FixQuotes(postBodyNode);
PostHtml = postBodyNode.InnerHtml;
HtmlNode profileLinksNode =
postNode.Descendants("td")
.FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Equals("postlinks"));
HtmlNode postRow =
postNode.Descendants("tr").FirstOrDefault();
if (postRow != null)
{
HasSeen = postRow.GetAttributeValue("class", string.Empty).Contains("seen");
}
User.IsCurrentUserPost =
profileLinksNode.Descendants("img")
.FirstOrDefault(node => node.GetAttributeValue("alt", string.Empty).Equals("Edit")) != null;
}
示例10: ClassesMatches
private bool ClassesMatches(HtmlNode node)
{
if (classes == null || classes.Length < 1)
{
return true;
}
string classString;
if ((classString = node.GetAttributeValue("class", null)) != null)
{
string[] nodeClasses = classString.Split(' ');
if (nodeClasses.Length <= 0) return false;
bool allMatch = false;
foreach (string filterClass in classes)
{
bool localMatch = false;
foreach (string nodeClass in nodeClasses)
{
if (filterClass == nodeClass)
{
localMatch = true;
}
}
allMatch = localMatch;
}
return allMatch;
}
return false;
}
示例11: GetLanguageFromHighlightClassAttribute
private string GetLanguageFromHighlightClassAttribute(HtmlNode node)
{
string val = node.GetAttributeValue("class", "");
var rx = new System.Text.RegularExpressions.Regex("highlight-([a-zA-Z0-9]+)");
var res = rx.Match(val);
return res.Success ? res.Value : "";
}
示例12: Parse
/// <summary>
/// Parses a thread HTML node to extract the information from it.
/// </summary>
/// <param name="threadNode">The thread HTML node.</param>
public void Parse(HtmlNode threadNode)
{
this.Name = WebUtility.HtmlDecode(threadNode.Descendants("a").FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Equals("thread_title")).InnerText);
this.KilledBy = threadNode.Descendants("a").LastOrDefault(node => node.GetAttributeValue("class", string.Empty).Equals("author")).InnerText;
this.IsSticky = threadNode.Descendants("td").Any(node => node.GetAttributeValue("class", string.Empty).Contains("title_sticky"));
this.IsLocked = threadNode.GetAttributeValue("class", string.Empty).Contains("closed");
this.CanMarkAsUnread = threadNode.Descendants("a").Any(node => node.GetAttributeValue("class", string.Empty).Equals("x"));
this.HasBeenViewed = this.CanMarkAsUnread;
this.Author = threadNode.Descendants("td").FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Equals("author")).InnerText;
if (threadNode.Descendants("a").Any(node => node.GetAttributeValue("class", string.Empty).Equals("count")))
{
this.RepliesSinceLastOpened = Convert.ToInt32(threadNode.Descendants("a").FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Equals("count")).InnerText);
}
if (threadNode.Descendants("td").Any(node => node.GetAttributeValue("class", string.Empty).Contains("replies")))
{
this.ReplyCount = Convert.ToInt32(threadNode.Descendants("td").FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("replies")).InnerText);
}
else
{
this.ReplyCount = 1;
}
// Isn't this user configurable?
this.TotalPages = (this.ReplyCount / 40) + 1;
this.Location = Constants.BASE_URL + threadNode.Descendants("a").FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Equals("thread_title")).GetAttributeValue("href",string.Empty) + Constants.PER_PAGE;
this.ThreadId = Convert.ToInt64(threadNode.Descendants("a").FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Equals("thread_title")).GetAttributeValue("href",string.Empty).Split('=')[1]);
this.ImageIconLocation = threadNode.Descendants("td").FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Equals("icon")).Descendants("img").FirstOrDefault().GetAttributeValue("src", string.Empty);
}
示例13: StineLinkTreeNode
public StineLinkTreeNode(HtmlNode node)
{
base.Text = HttpUtility.HtmlDecode(node.InnerHtml);
URL = node.GetAttributeValue("href", "not_found");
URL = HttpUtility.HtmlDecode(URL);
HTML_NODE = node;
}
示例14: VisitAsync
public async Task<HtmlNode> VisitAsync(VisitingContext context, HtmlNode node)
{
var src = node.GetAttributeValue("src", null);
if (src == null)
return node;
// Take care if the src starts with two slashes.
if (src.StartsWith("//"))
{
src = "http:" + src;
}
var srcUri = new Uri(src, UriKind.RelativeOrAbsolute);
if (!srcUri.IsAbsoluteUri)
{
srcUri = new Uri(context.Address, srcUri);
}
// Get the script and insert it inline.
var content = default(string);
try
{
content = await context.WebClient.DownloadAsync(srcUri);
}
catch (WebException)
{
return node;
}
content = "<script>" + content + "</script>";
return HtmlNode.CreateNode(content);
}
示例15: IsUnwantedLanguageDiv
private static bool IsUnwantedLanguageDiv(HtmlNode div)
{
return div.GetAttributeValue("class", "").Equals("libCScode")
&&
!div.Element("div").Element("div").InnerText.Trim().Equals("c#",
StringComparison.CurrentCultureIgnoreCase);
}