Can a website's generated HTML be saved using Canopy? Looking at the documentation under 'Getting Started' , I could not find anything related.
You can run arbitrary JavaScript using js
, document.documentElement.outerHTML
will return the current DOM, so
let html = js "return document.documentElement.outerHTML" |> string
does the trick.
Canopy is a wrapper around Selenium that provides some useful helper functions. But it also provides access to the Selenium IWebElement
instances in case you need them, via the element
function (halfway down the page; there don't seem to be internal anchors in that page so I couldn't link directly to the function). Then once you have the IWebElement
object, your problem becomes similar to this one , where the answer seems to be elem.getAttribute("innerHtml")
where elem
is the elememt whose content you want (which might even be the html
element). Note that the innerHtml
attribute is not a standard DOM attribute, so this won't work with all Selenium drivers; it will be dependent on which browser you're running in. But it apparently works on all major Web browsers.
See Get HTML Source of WebElement in Selenium WebDriver using Python for a related question using Python, which has more discussion about whether the innetHtml
attribute will work in all browsers. If it doesn't, Canopy also has the js
function, which you could leverage to run some Javascript to get the HTML you're looking for -- but if you're having trouble with that, you probably need to ask a Javascript question rather than an F# question.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.