使用 Selenium 加载 html body insideHTML

发布于 2025-01-13 11:05:13 字数 668 浏览 1 评论 0原文

我正在寻找一种将 HTML 正文加载到 selenium bot 中的方法,

html.body.innerHTML = .responseText

'
Set bot = New Selenium.ChromeDriver
bot.Get HERE

是否可以执行这样的任务,或者我必须将 html 正文保存到文件中然后导航到该文件?

我可以通过使用此过程将 html 正文导出到文件来管理此操作

Sub ExportHTML(sInput As String)
    With CreateObject("ADODB.Stream")
        .Charset = "UTF-8"
        .Open
        .WriteText sInput
        .SaveToFile Environ("USERPROFILE") & "\Desktop\OutputHTML.html", 2
        .Close
    End With
End Sub

之后,我可以使用 selenium 驱动程序加载文件,如下所示

bot.Get "file:///" & Environ("USERPROFILE") & "\Desktop\OutputHTML.html"

I am searching for a way to load the HTML body into selenium bot

html.body.innerHTML = .responseText

'
Set bot = New Selenium.ChromeDriver
bot.Get HERE

Is it possible to do such a task or I have to save the html body to a file then navigate to that file?

I could manage that by exporting the html body to a file using this procedure

Sub ExportHTML(sInput As String)
    With CreateObject("ADODB.Stream")
        .Charset = "UTF-8"
        .Open
        .WriteText sInput
        .SaveToFile Environ("USERPROFILE") & "\Desktop\OutputHTML.html", 2
        .Close
    End With
End Sub

After that I could load the file using the selenium driver like that

bot.Get "file:///" & Environ("USERPROFILE") & "\Desktop\OutputHTML.html"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌生 2025-01-20 11:05:13

您无法单独加载 HTML 正文,因为其核心表单中的 HTML 文档由两个强制部分组成:

  • < ;body>

简单 HTML 文档示例:

<html>
  <head>
    <title>Title of the document</title>
  </head>

  <body>
    <h1>This is a heading</h1>
    <p>This is a paragraph.</p>
  </body>

</html>

You can't load the HTML body seperately as the HTML Document in it's core form consists of two manadatory parts:

  • The <head>
  • The <body>

Example of a simple HTML document:

<html>
  <head>
    <title>Title of the document</title>
  </head>

  <body>
    <h1>This is a heading</h1>
    <p>This is a paragraph.</p>
  </body>

</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文