简体   繁体   English

使用Canopy保存生成的HTML

[英]Save generated HTML using Canopy

Can a website's generated HTML be saved using Canopy? 可以使用Canopy保存网站生成的 HTML吗? 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 您可以使用js运行任意JavaScript, document.documentElement.outerHTML将返回当前DOM,因此

let html = js "return document.documentElement.outerHTML" |> string

does the trick. 绝招。

Canopy is a wrapper around Selenium that provides some useful helper functions. Canopy是Selenium的包装,提供了一些有用的辅助功能。 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). 但是,如果需要它们,它还可以通过element函数 (在页面的IWebElement ;该页面中似乎没有内部锚,因此无法直接链接到该函数)提供对Selenium IWebElement实例的访问。 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). 然后,一旦有了IWebElement对象,您的问题就会变得与类似,答案似乎是elem.getAttribute("innerHtml") ,其中elem是您想要其内容的elememt(甚至可能是html元素)。 Note that the innerHtml attribute is not a standard DOM attribute, so this won't work with all Selenium drivers; 请注意, innerHtml属性不是标准的DOM属性,因此不适用于所有Selenium驱动程序。 it will be dependent on which browser you're running in. But it apparently works on all major Web browsers. 它取决于您运行的浏览器。但是,它显然适用于所有主要的Web浏览器。

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. 有关使用Python的相关问题,请参见使用Python在Selenium WebDriver中获取WebElement的HTML源。有关使用Python的相关问题,它有更多关于innetHtml属性是否适用于所有浏览器的讨论。 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. 如果没有,Canopy 具有js函数,您可以利用该函数运行一些Java脚本来获取所需的HTML -但是,如果遇到问题,则可能需要询问Java脚本问题而不是F#问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM