/// <summary> /// Loads HTML or URL information from specified filepath, and stores to <c>output</c> /// </summary> /// <param name="filepath">The filepath.</param> /// <param name="output">The output.</param> /// <returns></returns> internal static HtmlSourceAndUrl Load(String filepath, HtmlSourceAndUrl output = null) { if (output == null) { output = new HtmlSourceAndUrl(); } String ext = Path.GetExtension(filepath); ext = ext.Trim('.').ToLower(); switch (ext) { case HTML_EXTENSION: output.html = File.ReadAllText(filepath); output.filepath = filepath; break; case URL_EXTENSION: output.url = File.ReadAllText(filepath); break; default: break; } return(output); }
public Boolean IsEqual(HtmlSourceAndUrl other, Int32 tolerance) { if (other.html.isNullOrEmpty()) { return(false); } if (html.isNullOrEmpty()) { return(false); } if (html != other.html) { if (tolerance > 0) { Int32 change = other.html.Length - html.Length; if (Math.Abs(change) < tolerance) { return(true); } return(false); } else { return(false); } } if (url != other.url) { return(false); } return(true); }
public static String Save(HtmlDocument htmlDocument, String url, folderNode folder, String filename = "htmlsource") { HtmlSourceAndUrl item = new HtmlSourceAndUrl() { html = htmlDocument.DocumentNode.OuterHtml, url = url }; return(Save(item, folder, filename)); }
/// <summary> /// Saves the specified item /// </summary> /// <param name="item">The item.</param> /// <param name="folder">The folder.</param> /// <param name="filename">The filename.</param> public static String Save(this HtmlSourceAndUrl item, folderNode folder, String filename = "htmlsource") { String outputPath = folder.pathFor(filename + "." + HTML_EXTENSION, Data.enums.getWritableFileMode.autoRenameThis, "Saved HTML document"); File.WriteAllText(outputPath, item.html); String name = Path.GetFileNameWithoutExtension(outputPath); String urlContent = item.url; outputPath = folder.pathFor(filename + "." + URL_EXTENSION, Data.enums.getWritableFileMode.autoRenameThis, "Saved origin url for HTML document"); File.WriteAllText(outputPath, urlContent); return(outputPath); }
public static HtmlSourceAndUrl LoadSource(String filepath) { String filename = Path.GetFileNameWithoutExtension(filepath); String directory = Path.GetDirectoryName(filepath); DirectoryInfo di = new DirectoryInfo(directory); FileInfo[] filenames = di.GetFiles(filename + ".*", SearchOption.TopDirectoryOnly); var output = new HtmlSourceAndUrl(); foreach (var file in filenames) { Load(file.FullName, output); } return(output); }