public PageAnalysis CreatePageAnalysis(IPublishedContent node, string focusKeyword = null) { if (node == null) { throw new ArgumentNullException(nameof(node)); } var pageAnalysis = new PageAnalysis(); try { var htmlString = _templateHelper.GetNodeHtml(node); pageAnalysis.AbsoluteUrl = node.UrlAbsolute(); pageAnalysis.FocusKeyword = focusKeyword; pageAnalysis.Size = _byteSizeHelper.GetByteSize(htmlString); SetAnalyzerResults(pageAnalysis, htmlString); } catch (WebException ex) { pageAnalysis.Status = ((HttpWebResponse)ex.Response).StatusCode; } pageAnalysis.Score = _scoreService.GetScore(pageAnalysis); return(pageAnalysis); }
public PageInformation GetpageInformation(int id) { var pageInformation = new PageInformation(); var content = _typedPublishedContentQuery.TypedContent(id); var html = _templateHelper.GetNodeHtml(content); var htmlParser = new HtmlDocument(); htmlParser.LoadHtml(HttpUtility.HtmlDecode(html)); var headTag = htmlParser.DocumentNode.GetElements("head"); if (headTag.Any()) { var titleTags = headTag.First().GetElements("title"); if (titleTags.Any()) { pageInformation.Title = titleTags.First().InnerText; } } var metaTags = htmlParser.DocumentNode.GetElements("meta"); var attributeValues = from metaTag in metaTags let attribute = metaTag.GetAttribute("name") where attribute != null where attribute.Value == "description" select metaTag.GetAttribute("content"); if (attributeValues.Any()) { pageInformation.Description = attributeValues.First().Value; } pageInformation.Url = content.UrlWithDomain(); return(pageInformation); }