[英]C++/WinRT WinUI3: How to get html source code by WebView2?
I'm trying to use a webview2 control to get the body text of a website.我正在尝试使用 webview2 控件来获取网站的正文。 But nothing showed.
但是什么也没有显示。
My code:我的代码:
winrt::Windows::Foundation::IAsyncAction MainWindow::myButton_Click(IInspectable const&, RoutedEventArgs const&)
{
myButton().Content(box_value(L"Clicked"));
winrt::Microsoft::UI::Xaml::Controls::WebView2 web;
std::wstring uriToLaunch{ L"http://www.bing.com" };
Windows::Foundation::Uri uri{ uriToLaunch };
web.Source(uri);
co_await web.EnsureCoreWebView2Async();
winrt::hstring obj = co_await web.CoreWebView2().ExecuteScriptAsync(L"document.body.innerText");
TextBlock().Text(obj);
web.close();
}
Thank you indeed for your advise in advance.确实感谢您的提前建议。
You might need to change your script.您可能需要更改脚本。 It should be like ExecuteScriptAsync("document.documentElement.outerHTML;")
它应该像ExecuteScriptAsync("document.documentElement.outerHTML;")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.