是否可以将 Selenium 抓取的 HTML 源代码(使用 Excel VBA)存储到 HTMLDocument
中?元素?
这是一个使用 Microsoft Internet Controls
的示例和 Microsoft HTML Object Library
自动化 Internet Explorer。
Dim IE as InternetExplorer
Dim HTML as HTMLDocument
Set IE = New InternetExplorer
ie.navigate "www.google.com"
set HTML = IE.Document
Selenium 的圆顶也可以吗?例如像(不工作!):
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 的正确方法:
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
关于html - 将 Selenium HTML 源代码存储到 HTMLDocument 类型的元素中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34458767/