html - 将 Selenium HTML 源代码存储到 HTMLDocument 类型的元素中

标签 html vba excel selenium xhtml

是否可以将 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/

相关文章:

javascript - 无法在 AJAX 调用中设置 null 的属性 'innerHTML'

javascript - 根据日期禁用单选按钮

excel - VBA Excel 的比率条件要求

ms-access - Access 2000 - 删除多个表单?

vba - Excel 2010 Redim 保留崩溃

html - 如何使 Canvas 标签固定在位置而不随内容滚动?

javascript - 图像响应

excel - 将某个字符串从一列中的excel单元格复制到另一列

excel - 添加先前单元格和当前单元格功能

excel - 一起写 IF, AND, OR