[英]CefSharp documentcompleted
I am trying to use cefshar browser in C# winforms and need to know how I know when page completely loaded and how I can get browser document and get html elements,我正在尝试在 C# winforms 中使用 cefshar 浏览器,需要知道我如何知道页面何时完全加载以及如何获取浏览器文档并获取 html 元素,
I just Initialize the browser and don't know what I should do next:我只是初始化浏览器,不知道下一步该怎么做:
public Form1()
{
InitializeComponent();
Cef.Initialize(new CefSettings());
browser = new ChromiumWebBrowser("http://google.com");
BrowserContainer.Controls.Add(browser);
browser.Dock = DockStyle.Fill;
}
CefSharp has a LoadingStateChanged event with LoadingStateChangedArgs
. CefSharp有一个带有
LoadingStateChangedArgs
的LoadingStateChanged事件。
LoadingStateChangedArgs has a property called IsLoading
which indicates if the page is still loading. LoadingStateChangedArgs有一个名为
IsLoading
的属性,指示页面是否仍在加载。
You should be able to subscribe to it like this: 您应该能够像这样订阅它:
browser.LoadingStateChanged += OnLoadingStateChanged;
The method would look like this: 该方法如下所示:
private void OnLoadingStateChanged(object sender, LoadingStateChangedEventArgs args)
{
if (!args.IsLoading)
{
// Page has finished loading, do whatever you want here
}
}
I believe you can get the page source like this: 我相信你可以得到这样的页面源:
string HTML = await browser.GetSourceAsync();
You'd probably need to get to grips with something like HtmlAgility to parse it, I'm not going to cover that as it's off topic. 你可能需要掌握像HtmlAgility这样的东西来解析它,我不打算介绍它,因为它不是主题。
I ended up using:我最终使用:
using CefSharp;
wbAuthorization.AddressChanged += OnAddressChanged;
and和
private void OnAddressChanged(
object s,
AddressChangedEventArgs e)
{
if (e.Address.StartsWith(EndUri))
{
ResultUri = new Uri(e.Address);
this.DialogResult = DialogResult.OK;
}
}
EndUri
is the final page I want to examine and ResultUri
contains a string I want to extract later. EndUri
是我要检查的最后一页, ResultUri
包含我稍后要提取的字符串。 Just some example code from a larger class.只是来自更大的 class 的一些示例代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.