我想创建一个程序,可以通过C#登录到网站,但也使用默认浏览器。使用默认浏览器登录到网页c#
目前,它可以在窗体浏览器中正常工作,但我找不到代码以使其适用于实际的浏览器。
任何反馈表示赞赏,
using System;
using System.Windows.Forms;
using System.Diagnostics;
namespace PortalLogin2
{
public partial class Form1 : Form
{
bool mHooked;
public Form1()
{
InitializeComponent();
webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
}
private void button1_Click(object sender, EventArgs e)
{
string input = "https://en-gb.facebook.com/";
Process.Start(input);
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (mHooked) return;
HtmlDocument doc = webBrowser1.Document;
HtmlElement username = doc.GetElementById("email");
HtmlElement password = doc.GetElementById("pass");
HtmlElement submit = doc.GetElementById("u_0_");
string txtUser = "insert username here";
string txtPass = "insert password here";
doc.GetElementById("email").InnerText = txtUser.ToString();
doc.GetElementById("pass").InnerText = txtPass.ToString();
submit.InvokeMember("click");
mHooked = true;
}
}
}
的代码可能会被推广到了很多人,所以我需要到它的工作原理,以适应这个代码。谢谢你 –