c#登录机器人,. net Framework 4
本文关键字:Framework net 登录 机器人 | 更新日期: 2023-09-27 18:10:52
我想做一个简单的网络机器人,连接到目标网页,并填写登录数据,然后发送信息。不幸的是,我需要它与Windows XP兼容,所以我被迫使用。net Framework 4。
我知道登录栏和密码栏id从firebug。通常我会使用WebBrowser与GetElementById方法,但它不是一个选项。net 4。例如,在HttpWebRequest类中是否有其他方法可以做到这一点?
我不需要看到任何东西,只需要填写信息,然后能够在导航菜单上"点击"并下载一些数据。
编辑:添加not working afford
public void Send(string login, string password) { MyWebBrowser.Document.GetElementById("username_vmlogin"); //the GetElementById is red underlined in VS 2013 }
显示如下错误:
Error 1 'object' does not contain a definition for 'GetElementById' and no extension method 'GetElementById' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
WPF的WebBrowser是MSHTML WebBrowser控件的包装器。WPF WebBrowser的Document属性是一个'object',而不是像Windows窗体那样的强类型HtmlDocument。如文档所述,The Document object needs to be cast to the COM interface you are expecting.
。
Document
属性实现了几个IHTMLDocumenX接口。getElementById
在IHTMLDocument3中定义,这意味着你必须写:
IHTMLDocument3 doc=MyWebBrowser.Document;
IHTMLElement elt=doc.getElementById("abc");
可以通过使用动态变量来避免强制类型转换,例如:
dynamic doc=MyWebBrowser.Document;
dynamic elt=doc.getElementById("abc");
...