【问题标题】:Get current html from google chrome current tab从 google chrome 当前选项卡获取当前 html
【发布时间】:2013-03-08 07:01:12
【问题描述】:

我想做什么:
我想从 google chrome
我不想做的事情获取当前标签的 html:
获取当前标签url,然后使用webClient.DownloadString 获取html。 (我已经做到了)

从谷歌浏览器而不是从当前的谷歌浏览器网址获取 html 对我来说非常重要。
我尝试过的:

WebKit.NET

WebKit.NET 让我导航到 url like google chrome。
我想“connect”进入当前的谷歌浏览器窗口,然后进入当前标签窗口,将当前标签文档插入WebKit.DOM.Document

在我使用SHDocVw.ShellWindows(ShellWindows = 所有支持的窗口)的其他项目中,SHDocVw 让我获取internet explorer 的当前选项卡的当前 html。
示例:

    Dim shellWindows As New SHDocVw.ShellWindows
    For Each Ie As SHDocVw.InternetExplorer In shellWindows
            Dim htmlDoc As mshtml.HTMLDocument = Ie.Document
    Next


SHDocVw 仅与Internet Explorer 一起使用

如何在 chrome 选项卡之间浏览,然后将 html 插入字符串列表?
我怀疑答案在于WebKit.Interop.dll,但我对这个库没有经验。

我相信有人可以解决这个问题,
标签窗口的类名是Chrome_RenderWidgetHostHWND(使用spy++),
我认为我无法从当前标签 Handle 获取 html,
但也许我可以将句柄转换为 WebKit.DOM.Document - 但我更喜欢检查第一个选项。

以正确的方式和最好的方式完成项目对我来说非常重要。

【问题讨论】:

  • 你找到答案了吗?

标签: c# vb.net google-chrome webkit


【解决方案1】:

我认为您必须使用 WINAPI GetWindow。在那里您可以传递类名并获取当前窗口/进程的处理程序。我不直接知道这是否可行,但 Google Chrom 中的所有选项卡都在自己的线程中运行,所以我认为这是可能的。

Declare Function GetWindow Lib "user32.dll" Alias "GetWindow" ( ByVal hwnd As Long, ByVal wCmd  As Long) As Long
Declare Function SendMessage Lib "user32.dll" Alias "SendMessage" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Keys, ByVal lParam As Integer) As Long

这就是您需要的功能。然后你可以用第二个WINAPISendMessage向线程发送指令,并从侧面获取HTML。我认为您必须在选项卡内获取 HTML 框架的类名。或者也许你必须再次调用GetWindow 来获取 HTML 框架我不知道 Google Chrom 的结构,但我认为使用 spy++ 很容易获得类名。

【讨论】:

    猜你喜欢
    • 2023-04-06
    • 2021-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-12
    • 2013-04-24
    • 1970-01-01
    相关资源
    最近更新 更多