C#asp.net使用Windows窗体的WebBrowser [英] c# asp.net use Windows Forms WebBrowser

查看:741
本文介绍了C#asp.net使用Windows窗体的WebBrowser的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类库code的它使用一个System.Windows.Forms.WebBrowser控件加载一个网页,然后提取从DOM树等信息......我发现这是唯一的可靠的方式能够解析加载到页与JavaScript信息等...

I have a class of library code which uses a System.Windows.Forms.WebBrowser control to load a web page then extract information from the DOM tree, etc... I've found this to be the only reliable way to be able to parse information loaded onto a page with javascript, etc...

这与控制台应用程序进行测试时工作得很好,但是当我调用相同的方法,从一个asp.net页面(ASP.NET MVC控制器),它与ActiveX控件8856f961-340a-11D0-A96B-00c04fd705a2'崩溃不能被实例化,因为当前线程不在单线程公寓。......我尝试添加[STAThread]我的方法,但似乎并没有帮助!

This worked fine when testing with console app, but when I call the same method from an asp.net page (ASP.NET MVC Controller) it crashes with a "ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment."... i've tried adding [STAThread] to my method but that doesn't seem to help!

任何想法?

感谢

更新:

我需要让一个页面完成加载并执行其所有的JavaScript,然后搜索它符合我已经保存的模板......不要以为HtmlAgilityPack将工作文本?请问华廷运行的JavaScript?

I need to allow a page to complete load and execute all its javascript, then search it for text that matches a template I have already stored... Don't think HtmlAgilityPack will work? Does WatIn run the javascript?

推荐答案

保存自己很多头痛和使用华廷而不是一个WebBrowser控件。

Save yourself a lot of headache and use WatiN instead of a WebBrowser control.

请参阅这个问题:<一href=\"http://stackoverflow.com/questions/1549538/best-method-for-website-automation/1592325#1592325\">Best对于网站自动化的方法?

这篇关于C#asp.net使用Windows窗体的WebBrowser的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆