Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# .NET浏览器仿真API_C#_.net_Browser_Emulation - Fatal编程技术网

C# .NET浏览器仿真API

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

我正在搜索.NET库/组件,它将允许我执行以下操作:

  • 加载网页
  • 执行链接JS
  • 在页面范围内执行我自己的JS并返回执行结果,可以是复杂对象或对象数组
  • 到目前为止,我找到的唯一解决方案是使用WebBrowser对象,但它需要大量的样板代码才能使一切正常工作,而它无法处理对象数组。 在下面的代码示例中,我在
    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,工作起来很有魅力。 有一个免费的许可证,但也有一个商业许可证,如果需要,您可以购买源代码:-)

    • (也免费)