将Selenium HTML源代码存储到HTMLDocument类型的元素中 [英] Store Selenium HTML Source Code into element of type HTMLDocument
问题描述
是否可以将使用Selenium获取的HTML源代码(使用Excel VBA)存储到 HTMLDocument
元素中?
这是一个使用 Microsoft Internet控件
和 Microsoft HTML对象库
来自动化Internet Explorer的示例。
Is it possible to store the HTML source grabbed with Selenium (using Excel VBA) into a HTMLDocument
element?
This is an example using Microsoft Internet Controls
and Microsoft HTML Object Library
to automate Internet Explorer.
Dim IE as InternetExplorer
Dim HTML as HTMLDocument
Set IE = New InternetExplorer
ie.navigate "www.google.com"
set HTML = IE.Document
可以相同带硒的圆顶?例如像(不工作!):</ p>
can the same be dome with Selenium? For example something like (not working!):
Dim selenium As SeleniumWrapper.WebDriver
Set selenium = New SeleniumWrapper.WebDriver
Dim html as HTMLDocument
selenium.Start "firefox", "about:blank"
selenium.Open "file:///D:/webpages/LE_1001.htm"
Set html = selenium.getHtmlSource 'this is not working since .getHtmlSource()
'returns a String object but is there a way to store
'this html source into a type of HTMLDocument-element
推荐答案
使用SeleniumBasic获取DOM的正确方法:
The proper way to get the DOM with SeleniumBasic:
Sub Get_DOM()
Dim driver As New FirefoxDriver
driver.Get "https://en.wikipedia.org/wiki/Main_Page"
Dim html As New HTMLDocument ' Requires Microsoft HTML Library
html.body.innerHTML = driver.ExecuteScript("return document.body.innerHTML;")
Debug.Print html.body.innerText
driver.Quit
End Sub
使用上述示例获取日期的最新版本:
https://github.com/florentbr/SeleniumBasic/releases/latest
To get the latest version in date working with the above example: https://github.com/florentbr/SeleniumBasic/releases/latest
这篇关于将Selenium HTML源代码存储到HTMLDocument类型的元素中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!