//fetch the html as string string htmlAsString = webBrowser.SaveToString(); //create an html document from the string HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(htmlPage); htmlDocument.GetElementbyId("dynamicTitle").InnerHtml = javascript_tag;
HtmlDocument html = new HtmlDocument(); html.OptionWriteEmptyNodes = true; html.LoadHtml("<!DOCTYPE html><html><head><title>ttt</title></head><body></body></html>"); var ETagTable = html.CreateElement("table"); html.DocumentNode.Element("html").Element("body").AppendChild(ETagTable); ETagTable.InnerHtml = "<tr><th>Reference:</th><td><input type=\"text\" size=\"30\"" +"maxlength=\"32\" value=\"\" /></td></tr>"; html.LoadHtml(html.DocumentNode.OuterHtml); //<-- Reload the document Console.WriteLine(html.DocumentNode.InnerHtml);
HtmlDocument document = new HtmlDocument(); document.Load(downloadedHtml); XPathNavigator n = document.CreateNavigator(); XPathNodeIterator scriptTags = n.Select("//script"); foreach (XPathNavigator nav in scriptTags) { string innerXml = nav.InnerXml; // Parse inner xml using regex }
HtmlDocument doc = new HtmlDocument(); doc.Load("file.htm"); foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href"]) { }
public Importable translate(Node resourceNode, Document descriptor, String contextPath, String archiveBasePath) { String content = XPathHelper.getNodeValue("/CONTENT/BODY/TEXT", descriptor); String title = XPathHelper.getNodeValue("/CONTENT/TITLE/@value", descriptor).replaceAll("/", "_"); int priority = Integer.parseInt(((Element)resourceNode).getAttribute("priority")); // HTML docs in the archive have the < character replaced with the equivalent HTML entity // Without this, the TEXT node contents would be treated as sub-nodes. content.replaceAll("<", "<"); contextPath = contextPath + title; //Validator.escapeResourceName(title); HtmlDocument html = new HtmlDocument(); html.setContent(content); html.setTitle(title); html.setContextPath(contextPath); html.setSequenceNum(priority); return html; }
HtmlDocument html = new HtmlDocument(); html.OptionWriteEmptyNodes = true; html.Load("page.htm"); html.DocumentNode.Element("html").Element("body").InnerHtml = "<input type=\"text\" />"; html.LoadHtml(html.DocumentNode.OuterHtml); //Reload the document
using OpenQA.Selenium; ..... IWebDriver driver = new PhantomJS.PhantomJSDriver(); driver.Navigate().GoToUrl(url); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(driver.PageSource);
HtmlDocument doc = new HtmlDocument(); doc.OptionWriteEmptyNodes = true; HtmlNode nodeDiv = doc.CreateElement("div"); nodeDiv.InnerHtml = "<table><tr><th>Reference:</th></tr><tr><td><input type='text' id='e.crm_reference' size='30' maxlength='32' value='' /></td></tr></table>";
var doc = new HtmlDocument(); doc.LoadHtml(html); foreach(var node in doc.DocumentNode.SelectNodes("//div|//span|//p")) if (string.IsNullOrWhiteSpace(node.InnerText.Replace(@"\n", string.Empty))) node.Remove(); var result = doc.DocumentNode.OuterHtml;
public Importable translate(Node resourceNode, Document descriptor, String contextPath, String archiveBasePath) { if (resourceNode.hasChildNodes() && (resourceNode.getChildNodes().getLength() > 1)) { // this is a compound document, and it's already being handled by the Blackboard55FileParser return null; } if (XPathHelper.selectNodes("//STARTASSESSMENT", descriptor).size() > 0) { // this signifies a document that serves as a link to an assessment // these links aren't meaningful in the Sakai context return null; } String content = XPathHelper.getNodeValue("//TEXT", descriptor); String title = XPathHelper.getNodeValue("/CONTENT/TITLE", descriptor); int priority = Integer.parseInt(((Element)resourceNode).getAttribute("priority")); // HTML docs in the archive have the < character replaced with the equivalent HTML entity // Without this, the TEXT node contents would be treated as sub-nodes. content.replaceAll("<", "<"); contextPath = contextPath + title.replaceAll("/", "_"); //Validator.escapeResourceName(title); HtmlDocument html = new HtmlDocument(); html.setContent(content); html.setTitle(title); html.setContextPath(contextPath); html.setSequenceNum(priority); return html; }
// Initialize the Chrome Driver (or any other supported browser) using (var driver = new ChromeDriver()) { // open the target page driver.Navigate().GoToUrl("the_targt_page_url_here"); //maybe add selenium waits if needed, //to wait until certain element appear in the page //pass the HTML page to HAP's HtmlDocument HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(driver.PageSource); }
HtmlDocument doc = new HtmlDocument(); doc.Load("file.htm"); foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href"]) { HtmlAttribute att = link["href"]; att.Value = FixLink(att); } doc.Save("file.htm");
var html = new HtmlDocument(); html.LoadHtml(@" <html>
protected Importable getCompanionForCompoundDocument(Document resourceDescriptor, Folder folder) { HtmlDocument html = new HtmlDocument(); StringBuffer content = new StringBuffer(); List<Node> fileNodes = XPathHelper.selectNodes("/CONTENT/FILES/FILE", resourceDescriptor); content.append("<html>\n"); content.append(" <head><title>" + folder.getTitle() + "</title></head>\n"); content.append(" <body>\n"); content.append(" <p>" + XPathHelper.getNodeValue("/CONTENT/BODY/TEXT", resourceDescriptor) + "</p>\n"); content.append(" <table border=\"1\">\n"); for (Node fileNode : fileNodes) { String fileName = XPathHelper.getNodeValue("./NAME", fileNode); content.append(" <tr><td><a href=\""+ folder.getTitle() + "/" + fileName + "\">" + fileName + "</a></td></tr>\n"); } content.append(" </table>\n"); content.append(" </body>\n"); content.append("</html>"); html.setContent(content.toString()); html.setTitle(folder.getTitle()); html.setContextPath(folder.getPath() + folder.getTitle() + "_manifest"); html.setLegacyGroup(folder.getLegacyGroup()); // we want the html document to come before the folder in sequence html.setSequenceNum(folder.getSequenceNum() - 1); return html; }
HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(sourceCode); var node = doc.DocumentNode; var nodes = node.SelectNodes("//a"); doc = new HtmlDocument(); doc.LoadHtml(sourceCode); node = doc.DocumentNode; nodes = node.SelectNodes("//a");
public Document CreateDocument(String type){ if (type.isEqual("html")) return new HtmlDocument(); if (type.isEqual("proprietary")) return new MyDocument(); if (type.isEqual("pdf")) return new PdfDocument (); }
public Importable translate(Node resourceNode, Document descriptor, String contextPath, String archiveBasePath) { HtmlDocument rv = new HtmlDocument(); String lastName = XPathHelper.getNodeValue("/STAFFINFO/CONTACT/NAME/FAMILY/@value", descriptor); String firstName = XPathHelper.getNodeValue("/STAFFINFO/CONTACT/NAME/GIVEN/@value", descriptor); rv.setContent(page.toString().replaceAll("<", "<")); rv.setTitle(title); rv.setContextPath(contextPath); rv.setSequenceNum(priority); return rv;
protected Importable getCompanionForCompoundDocument(Document resourceDescriptor, Folder folder) { HtmlDocument html = new HtmlDocument(); StringBuffer content = new StringBuffer(); List<Node> linkFileNodes = XPathHelper.selectNodes("//FILEREF/FILEACTION[@value='link']/parent::node()", resourceDescriptor); html.setContent(content.toString()); html.setTitle(folder.getTitle()); html.setContextPath(folder.getPath() + folder.getTitle() + "_manifest"); html.setLegacyGroup(folder.getLegacyGroup()); html.setSequenceNum(folder.getSequenceNum() - 1); return html;