C# .NET浏览器仿真API
我正在搜索.NET库/组件,它将允许我执行以下操作:C# .NET浏览器仿真API,c#,.net,browser,emulation,C#,.net,Browser,Emulation,我正在搜索.NET库/组件,它将允许我执行以下操作: 加载网页 执行链接JS 在页面范围内执行我自己的JS并返回执行结果,可以是复杂对象或对象数组 到目前为止,我找到的唯一解决方案是使用WebBrowser对象,但它需要大量的样板代码才能使一切正常工作,而它无法处理对象数组。 在下面的代码示例中,我在dynamic val=o.a上收到一个RuntimeBinderException class Program { [STAThread] static void Main(str
dynamic val=o.a上收到一个RuntimeBinderException代码>
class Program
{
[STAThread]
static void Main(string[] args)
{
var t = new System.Threading.Thread(BrowserThread);
t.SetApartmentState(System.Threading.ApartmentState.STA);
t.Start();
Console.ReadLine();
}
private static void BrowserThread()
{
var wb = new WebBrowser();
wb.Navigate("http://google.com");
wb.DocumentCompleted += (sender, args) =>
{
var head = wb.Document.GetElementsByTagName("head")[0];
var script = wb.Document.CreateElement("script");
dynamic el = script.DomElement;
el.text = "function test(){return [{a:2},{a:2},{a:2}]}";
head.AppendChild(script);
dynamic result = wb.Document.InvokeScript("test");
dynamic o = result.pop();
dynamic val = o.a;
};
Application.Run();
}
}
有人能提供替代解决方案或帮助修复此问题吗?您可以尝试动态a=o[0].a代码>或动态a=结果[0].a代码>并查看这是否有帮助
另一点:您应该通过单步遍历代码来检查结果的类型。。。这可能有助于找到一个有效的答案
关于替代方案,有一些选择:
- (免费)
它基于Chrome/WebKit,工作起来很有魅力。
有一个免费的许可证,但也有一个商业许可证,如果需要,您可以购买源代码:-)
- (也免费)