使用 Chromium/WebKit 从页面获取 DOM
渲染后尝试访问页面的 DOM。我不需要查看该页面,并计划以编程方式应用此功能,而无需任何 GUI 或交互。
我对后期渲染感兴趣的原因是我想知道对象出现在哪里。一些位置信息是在 HTML 中编码的(例如,通过 offsetLeft),但很多位置信息不是这样。而且,Javascript可以改变最终的定位。我希望位置尽可能接近用户所看到的。
我研究了 Chromium 代码,认为有一种方法可以做到这一点,但没有足够的文档来开始。
简而言之,我对这样的伪代码很感兴趣:
DOMRoot *r = new Page("http://stackoverflow.com")->getDom();
关于起点的任何提示?
Trying to get access to a page's DOM after rendering. I do not need to view the page and plan to apply this programmatically without any GUI or interaction.
The reason I am interested in post-rendering is that I want to know where objects appear. Some location information is coded in the HTML (e.g., via offsetLeft), but much is not. Also, Javascript can change the ultimate positioning. I want positions that are as close to what the user will see as possible.
I've looked into Chromium code and think there is a way to do this but there is not enough documentation to get started.
Putting it VERY simply I'd be interested in pseudo-code like this:
DOMRoot *r = new Page("http://stackoverflow.com")->getDom();
Any tips on starting points?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用 Chromium 公开的 Web API 包装器;具体来说, WebDocument 类包含您可以使用的功能需要。你可以这样调用它:
你可以浏览 Chromium 的 Web API 的源代码此处的包装器。 虽然文档不多,但头文件的注释相当完善,您可以浏览 Chrome 的源代码来查看 API 的实际情况。
开始使用 Chromium 很困难。我建议查看 test_shell 应用程序。此外,像 Chromium 嵌入式框架 (CEF) 这样的框架简化了将 Chromium 嵌入到您的申请;我在当前的项目中使用了CEF,我对它非常满意。
You should use the Web API wrapper that Chromium exposes; specifically, the WebDocument class contains the functionality that you need. You can call it like this:
You can browse the source code for Chromium's Web API wrapper here. Although there's not much in the way of documentation, the header files are fairly well-commented and you can browse Chrome's source code to see the API in action.
It's difficult to get started using Chromium. I recommend looking at the test_shell application. Also, a framework like the Chromium Embedded Framework (CEF) simplifies the process of embedding Chromium in your application; I use CEF in my current project and I'm very satisfied with it.