Пример #1
0
 private static void SaveHtmlAndScreenShot(Uri uri, RemoteWebDriver _driver)
 {
     try
     {
         var removeScriptTag =
             "Array.prototype.slice.call(document.getElementsByTagName('script')).forEach(function(item) { item.parentNode.removeChild(item);});";
         var addClassToBody = "document.getElementsByTagName('body')[0].className += ' seoPrerender';";
         
         _driver.ExecuteScript(removeScriptTag + addClassToBody);   
         //uri.AbsolutePath is relative url
         var result = _driver.PageSource;
         string filenameWithPath = _options.FolderPath + uri.AbsolutePath + MakeValidFileName(uri.Query);
         Directory.CreateDirectory(Path.GetDirectoryName(filenameWithPath));
         File.WriteAllText(filenameWithPath + ".html", result);
         logger.Info("SaveHtmlAndScreenShot to {0}.html", filenameWithPath);
         _driver.GetScreenshot().SaveAsFile(filenameWithPath + ".jpg", ImageFormat.Jpeg);
     }
     catch (Exception ex)
     {
         logger.Error(ex);
     }
 }
 public Screenshot TakeScreenShot(RemoteWebDriver webDriver)
 {
     return webDriver.GetScreenshot();
 }