我想創建一個程序,可以通過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;
}
}
}
的代碼可能會被推廣到了很多人,所以我需要到它的工作原理,以適應這個代碼。謝謝你 –