private void ExtractAnchorLink(int startTag) { HtmlNode node = GetNode(startTag); string url = node.GetAttributeValue(HtmlAttributeId.Href); if (url != null && url.Length > 0) { LinkItem linkItem = new LinkItem(); linkItem.LinkSource = LinkSourceType.Anchor; linkItem.Url = url; int endTag = parsedHtml.FindEndTag(startTag + 1, GetNode(startTag).TagId); // This is to avoid <A> ....<A> .... </A> for (int i = startTag + 1; i < endTag; i++) { if (IsLinkSeparator(parsedHtml.Nodes[i])) { endTag = i; break; } } if (endTag > 0 && endTag < parsedHtml.Nodes.Count) { linkItem.AnchorText = parsedHtml.TextBetween(startTag, endTag); //linkItem.NodeStack = GetNodeStack(startTag, endTag); linkItem.LeftText = GetLeftNearText(startTag); linkItem.RightText = GetRightNearText(endTag); } AddLink(linkItem); } }
private void ExtractImageLink(int startTag) { HtmlNode node = GetNode(startTag); string url = node.GetAttributeValue(HtmlAttributeId.Src); if (url != null && url.Length > 0) { string anchorText = ""; string alt = node.GetAttributeValue(HtmlAttributeId.Alt); if (alt != null) { anchorText = alt; } string title = node.GetAttributeValue(HtmlAttributeId.Title); if (title != null) { if (string.IsNullOrEmpty(anchorText)) { anchorText = title; } else { anchorText = anchorText + ";;" + title; } } LinkItem linkItem = new LinkItem(); linkItem.LinkSource = LinkSourceType.Image; linkItem.Url = url; linkItem.AnchorText = anchorText; AddLink(linkItem); } }
private void AddLink(LinkItem linkItem) { string url = LinkExtractor.NormalizeUrl(linkItem.Url); if (url != null) { linkItem.Url = url; parsedHtml.Links.Add(linkItem); } }
private void ExtractLinkLink(int startTag) { HtmlNode node = GetNode(startTag); string url = node.GetAttributeValue(HtmlAttributeId.Src); if (url != null && url.Length > 0) { LinkItem linkItem = new LinkItem(); linkItem.LinkSource = LinkSourceType.Link; linkItem.Url = url; AddLink(linkItem); } }
private void ExtractAreaLink(int startTag) { HtmlNode node = GetNode(startTag); string url = node.GetAttributeValue(HtmlAttributeId.Href); if (url != null && url.Length > 0) { string anchorText = ""; AttributeItem attribute = node.GetAttribute(HtmlAttributeId.Alt); if (attribute != null) { anchorText = attribute.Value; } LinkItem linkItem = new LinkItem(); linkItem.LinkSource = LinkSourceType.Area; linkItem.Url = url; linkItem.AnchorText = anchorText; AddLink(linkItem); } }