English 中文(简体)
C# WebBrowser Invoke 问题
原标题:C# WebBrowser Invoke issue
  • 时间:2010-03-27 12:27:42
  •  标签:
  • c#

我正在使用一个网络浏览器把我录入脸书。 一切都可行,但问题是,当我援引纽特语时,我需要检查密码是否正确,但是,在援引纽特语之前,检查似乎根本就没有意义,因为查询代码是在援引后。

private void Facebook_Login(String username, String password)
    {
        webBrowser1.Url = new Uri("http://m.facebook.com");

        while (webBrowser1.ReadyState != WebBrowserReadyState.Complete) Application.DoEvents();

        HtmlElementCollection inputs = webBrowser1.Document.GetElementsByTagName("input");
        foreach(HtmlElement input in inputs)
        {
            if (input.GetAttribute("name") == "email") 
            {
                input.SetAttribute("value", "jamesjeffery@hotmail.co.uk");
            }
            if (input.GetAttribute("name") == "pass")
            {
                input.SetAttribute("value", "kelaroostj"); // dont worry that pass wont work lol.
            }
            if (input.GetAttribute("name") == "login")
            {
                input.InvokeMember("click");
            }
        }

        while (webBrowser1.ReadyState != WebBrowserReadyState.Complete) Application.DoEvents();

        HtmlElementCollection bs = webBrowser1.Document.GetElementsByTagName("b");
        foreach(HtmlElement b in bs)
        {
            MessageBox.Show(b.InnerHtml);
        }

        Log_Message("Logged into Facebook with: jamesjeffery@hotmail.co.uk");
    }
问题回答

这是因为你正在穿透所有超文本元素。 你在“逻辑”令中刚刚有了这一守则,这并不意味着超文本部分的捕获也有。

如果“超声望”是行文中的第一个要素,则首先要点击纽子。

HtmlElement Username = Browsers[0].Document.GetElementById("name");
HtmlElement Password = Browsers[0].Document.GetElementById("pass");
HtmlElement LoginBtn = Browsers[0].Document.GetElementById("login");

Username.SetAttribute("value", "jamesjeffery@hotmail.co.uk");
Password.SetAttribute("value", "kelaroostj");
LoginBtn.InvokeMember("click");

假设这些要素的识别与上述内容相同。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签