简体   繁体   English

如何使用webbrowser控件登录网站

[英]How to login to website using webbrowser control

I need to programmtically key in the username, password for a website using Webbrowser control in Visual Basic 6.0 application (please note it is not .Net application) and also click on Login button. 我需要在Visual Basic 6.0应用程序中使用Webbrowser控件以编程方式键入用户名,密码(请注意它不是.Net应用程序)并单击“登录”按钮。

Also I am not trying to hack or spam. 此外,我不是想破解或垃圾邮件。 The requirement is part of interfacing that I am trying to create between multiple applications. 该要求是我尝试在多个应用程序之间创建的接口的一部分。

Please let me know how to go about this. 请让我知道如何解决这个问题。

Thanks 谢谢

You can use the Document property of the WebBrowser control to interact with the HTML page. 您可以使用WebBrowser控件的Document属性与HTML页面进行交互。 In your case, it would depend on the structure of the web site, but you should be able to do something like this (untested) 在你的情况下,它将取决于网站的结构,但你应该能够做这样的事情(未经测试)

With webBrowser.Document.forms(1)
    .getElementByName("username").value = "username"
    .getElementByName("password").value = "password"
    .submit()
End With

I think you should use some HTTP request and store the returned cookie (there probably will be one). 我认为你应该使用一些HTTP请求并存储返回的cookie(可能会有一个)。 Observe the login process on the page if it's GET or POST method, and if it uses a cookie. 如果它是GET或POST方法,则观察页面上的登录过程,如果它使用cookie。 I don't think you need webbrowser control for this. 我认为你不需要webbrowser控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM