在某些 jquery 更新了某些内容后,我想获取加载到 webview 中的页面的实际内容
$(document).ready(function() {
$("#main").append('<p>Test</p><p>Test</p><p>Test</p><p>Test</p><p>Test</p><p>Test</p><p>Test</p>');
});
页面更新后,我尝试使用以下命令 [vala syntax] 获取页面内容
web_view.get_main_frame ().get_data_source().get_data().str
但我只得到原始内容(即使加载完成)
使用
web_view.get_dom_document().document_element.text_content
我得到了实际的内容,但标签被删除了。
我想我可以走整棵树来获取实际的文档,但应该是一种更简单的方法。
编辑:我的解决方案
this.web_view.load_finished.connect ((source, frame) => {
stderr.printf(this.web_view.get_dom_document().body.get_inner_html());
}
几年后当我读到这篇文章时,我可能会觉得这很糟糕,但现在我会继续下去。