gpt4 book ai didi

c# - CefSharp-获取HTML元素的值

转载 作者:行者123 更新时间:2023-12-03 16:44:16 43 4
gpt4 key购买 nike

如何使用CefSharp获取HTML元素的值?

我知道如何使用此默认WebBrowser控件:

Dim Elem As HtmlElement = WebBrowser1.Document.GetElementByID("id")

但是我没有为CefSharp找到任何类似的东西。我使用CefSharp的主要原因是因为网站的一部分正在使用iframe存储源,而默认的WebBrowser不支持它。另外,CefSharp是否可以选择InvokeMember或类似的调用?

顺便说一下,我正在使用最新版本的CefSharp。

最佳答案

他们的常见问题解答中有一个很好的例子。

https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions#2-how-do-you-call-a-javascript-method-that-return-a-result

这是懒惰的代码。自我解释,对我来说效果很好。

string script = string.Format("document.getElementById('startMonth').value;");
browser.EvaluateScriptAsync(script).ContinueWith(x =>
{
var response = x.Result;

if (response.Success && response.Result != null)
{
var startDate = response.Result;
//startDate is the value of a HTML element.
}
});

关于c# - CefSharp-获取HTML元素的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37712962/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com