如何填写,并在使用Windows应用程序中的第三方网站提交网页表单? [英] How to fill and submit a web form on a third party website using windows application?

查看:146
本文介绍了如何填写,并在使用Windows应用程序中的第三方网站提交网页表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做的一个项目中,我必须做出一个Windows应用程序,它可以从用户处获得一个网址的文本框。现在,当用户preSS继续按钮,应用程序应该打开URL在WebBrowser控件,并填写包含用户ID和放大器,页面的表单;密码文本框,并通过该网页上的登录按钮提交。现在,我的应用程序应该显示的下一个页面中的WebBrowser控件的用户。

I am doing a project in which I have to make a windows application that can Take a URL in textbox from user. Now when the user press the Proceed button, the application should open that URl in a webbrowser control and fill the form on that page containing userID & password textboxes and submit it via the login button on that web page. Now my application should show the next page in that webbrowser control to the user.

我可以通过我的C#code。打开网址在应用程序的web浏览器的控制,但我不能算出它是如何找到用户ID和放大器;这是在我的应用程序的WebBrowser控件当前打开的网页上pasword文本框,如何填补他们,如何找到登录按钮和放大器;如何通过我的C#code。单击它。

I can open the url in the application's webbrowser control through my C# Code, but I can't figure it out that how to find the userID & pasword textboxes on that web page that is currently opened in the webbrowser control of my application, how to fill them, how to find the login button & how to click it through my C# Code.

推荐答案

有关这一点,你将不得不寻找到第三方网站的网页源代码,找到用户名,密码文本框的ID,并提交按钮。 (如果你提供一个链接,我会帮你了解一下)。然后用这个code:

For this you will have to look into the page source of the 3rd party site and find the id of the username, password textbox and submit button. (If you provide a link I would check it for you). Then use this code:

//add a reference to Microsoft.mshtml in solution explorer
using mshtml;

private SHDocVw.WebBrowser_V1 Web_V1;

Form1_Load()
{
    Web_V1 = (SHDocVw.WebBrowser_V1)webBrowser1.ActiveXInstance;
}

webBrowser1_Document_Complete()
{
if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
    {
        if (webBrowser1.Url.ToString() == "YourLoginSite.Com")
        {
            try
            {
                HTMLDocument pass = new HTMLDocument();
                pass = (HTMLDocument)Web_V1.Document;
                HTMLInputElement passBox = (HTMLInputElement)pass.all.item("PassIDThatyoufoundinsource", 0);
                passBox.value = "YourPassword";
                HTMLDocument log = new HTMLDocument();
                log = (HTMLDocument)Web_V1.Document;
                HTMLInputElement logBox = (HTMLInputElement)log.all.item("loginidfrompagesource", 0);
                logBox.value = "yourlogin";
                HTMLInputElement submit = (HTMLInputElement)pass.all.item("SubmitButtonIDFromPageSource", 0);
                submit.click();
            }
            catch { }
        }
    }
}

这篇关于如何填写,并在使用Windows应用程序中的第三方网站提交网页表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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