将Selenium HTML源代码存储到HTMLDocument类型的元素中 [英] Store Selenium HTML Source Code into element of type HTMLDocument

查看:479
本文介绍了将Selenium HTML源代码存储到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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆