Advertisement
Guest User

Untitled

a guest
May 19th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Threading.Tasks;
  8. using HtmlAgilityPack;
  9. using Microsoft.AspNetCore.Mvc;
  10. using Seo.Models;
  11. using Seo.Utilities;
  12.  
  13. namespace Seo.Controllers
  14. {
  15. public class HomeController : Controller
  16. {
  17. private readonly ITitleTagValidate _titleTagValidate;
  18. private readonly Ih1h6TagsValidate _h1h6TagsValidate;
  19. private readonly IKeyWordValidate _keyWordValidate;
  20. private readonly IPicturesAltValidate _picturesAltValidate;
  21. private readonly IWebsiteContentValidate _websiteContentValidate;
  22. private readonly IDescriptionValidate _descriptionValidate;
  23. private readonly IExternalFilesValidate _externalFilesValidate;
  24. private readonly ISslValidate _sslValidate;
  25.  
  26.  
  27. public HomeController(ITitleTagValidate titleTagValidate, IKeyWordValidate keyWordValidate, IWebsiteContentValidate websiteContentValidate, IPicturesAltValidate picturesAltValidate, IDescriptionValidate descriptionValidate, IExternalFilesValidate externalFilesValidate, ISslValidate sslValidate, Ih1h6TagsValidate h1h6TagsValidate)
  28. {
  29. _titleTagValidate = titleTagValidate;
  30. _h1h6TagsValidate = h1h6TagsValidate;
  31. _keyWordValidate = keyWordValidate;
  32. _picturesAltValidate = picturesAltValidate;
  33. _websiteContentValidate = websiteContentValidate;
  34. _descriptionValidate = descriptionValidate;
  35. _externalFilesValidate = externalFilesValidate;
  36. _sslValidate = sslValidate;
  37. }
  38. [HttpGet]
  39. public IActionResult Index()
  40. {
  41. return View();
  42. }
  43.  
  44. [HttpPost]
  45. public IActionResult Index(string url)
  46. {
  47. var web = new HtmlWeb();
  48. var document = web.Load(url);
  49. h1h6TagsValidate h = new h1h6TagsValidate();
  50. Website website = new Website();
  51. string websideContent = document.DocumentNode.OuterHtml;
  52. var htmlBody = document.DocumentNode.SelectSingleNode("//body");
  53. var nodes = document.DocumentNode.SelectNodes("//h1");
  54.  
  55. string titleTagFromWebside = document.DocumentNode.SelectSingleNode("//head/title")?.WriteContentTo();
  56. website.titleTag = _titleTagValidate.TitleTagChecker(titleTagFromWebside);
  57. website.h1Tag = _h1h6TagsValidate.h1h6TagsChecker(document.DocumentNode.SelectNodes("//h1"));//nodes);
  58. website.h2Tag = _h1h6TagsValidate.h1h6TagsChecker(document.DocumentNode.SelectNodes("//h2"));
  59. website.h3Tag = _h1h6TagsValidate.h1h6TagsChecker(document.DocumentNode.SelectNodes("//h3"));
  60. website.h4Tag = _h1h6TagsValidate.h1h6TagsChecker(document.DocumentNode.SelectNodes("//h4"));
  61. website.h5Tag = _h1h6TagsValidate.h1h6TagsChecker(document.DocumentNode.SelectNodes("//h5"));
  62. website.h6Tag = _h1h6TagsValidate.h1h6TagsChecker(document.DocumentNode.SelectNodes("//h6"));
  63. var topWords = _keyWordValidate.WordCounting(document.DocumentNode.InnerText);
  64. var topWordsSorted = _keyWordValidate.WordSorting(topWords);
  65. website.pageContent = topWordsSorted;
  66. website.altPicturesTags = _picturesAltValidate.CheckAltAttributes(document.DocumentNode.SelectNodes("//img"));
  67. website.facebook = _websiteContentValidate.CheckWebsideContent(websideContent,"facebook");
  68. website.twitter = _websiteContentValidate.CheckWebsideContent(websideContent, "twitter");
  69. website.instagram = _websiteContentValidate.CheckWebsideContent(websideContent, "instagram");
  70. website.linkedin = _websiteContentValidate.CheckWebsideContent(websideContent, "linkedin");
  71. website.descriptionPage = _descriptionValidate.CheckDescriptionLength(document);
  72. website.robots = _externalFilesValidate.CheckExternalFilesExist(url + "/robots.txt");
  73. website.sitemap = _externalFilesValidate.CheckExternalFilesExist(url + "/sitemap.xml");
  74. website.favicon = _externalFilesValidate.CheckExternalFilesExist(url + "/favicon.ico");
  75. website.noindex = _websiteContentValidate.CheckWebsideContent(websideContent, "noindex");
  76. website.canonical = _websiteContentValidate.CheckWebsideContent(websideContent, "canonical");
  77. website.analytics = _websiteContentValidate.CheckWebsideContent(websideContent, "googletagmanager");
  78. website.ssl = _sslValidate.SslCheckExist(url);
  79.  
  80. return View("SourceView",website);
  81. }
  82.  
  83. public StreamReader HTTPRequest(String url)
  84. {
  85. HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
  86. HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
  87. StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream());
  88. return streamReader;
  89. }
  90.  
  91. public String PrintHTTPRequest(StreamReader streamReader)
  92. {
  93. string pageContent = "";
  94. while(!streamReader.EndOfStream)
  95. {
  96. pageContent += streamReader.ReadLine().ToString();
  97. }
  98. return pageContent;
  99. }
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement