C# 如何使用windows窗体登录基于javascript的站点?
我一直试图通过使用C# 如何使用windows窗体登录基于javascript的站点?,c#,javascript,C#,Javascript,我一直试图通过使用GetElementByTag/GetElemenByName方法,使用WebBrowser控件自动登录到一个站点,但没有太大成功。(WFA-C#) 我相信主要的原因是这个网站是用JavaScript编写的 我做了一些研究,发现了两种方法: 通过模仿网站登录表单,我可以使用一种叫做POST的东西。(或类似的东西) 将javascript输入注入站点中的所有输入字段 我不知道如何解决这个问题,而且由于我完全缺乏javaScript或任何基于web的编程经验,我真的可以对手头的问题
GetElementByTag
/GetElemenByName
方法,使用WebBrowser控件自动登录到一个站点,但没有太大成功。(WFA-C#)
我相信主要的原因是这个网站是用JavaScript编写的
我做了一些研究,发现了两种方法:
我试图访问的站点是-“…也许我的方法错了?!” 您可以使用web浏览器控件,只需在目标页面上找到元素id并填充它们即可 我给你写了一个简单的例子:
public Form1()
{
InitializeComponent();
//navigate to you destination
webBrowser1.Navigate("https://www.certiport.com/portal/SSL/Login.aspx");
}
bool is_sec_page = false;
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (!is_sec_page)
{
//get page element with id
webBrowser1.Document.GetElementById("c_Username").InnerText = "username";
webBrowser1.Document.GetElementById("c_Password").InnerText = "pass";
//login in to account(fire a login button promagatelly)
webBrowser1.Document.GetElementById("c_LoginBtn_c_CommandBtn").InvokeMember("click");
is_sec_page = true;
}
//secound page(if correctly aotanticate
else
{
//intract with sec page elements with theire ids
}
}
public Form1()
{
InitializeComponent();
//navigate to you destination
webBrowser1.Navigate("https://www.certiport.com/portal/SSL/Login.aspx");
}
bool is_sec_page = false;
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (!is_sec_page)
{
//get page element with id
webBrowser1.Document.GetElementById("c_Username").InnerText = "username";
webBrowser1.Document.GetElementById("c_Password").InnerText = "pass";
//login in to account(fire a login button promagatelly)
webBrowser1.Document.GetElementById("c_LoginBtn_c_CommandBtn").InvokeMember("click");
is_sec_page = true;
}
//secound page(if correctly aotanticate
else
{
//intract with sec page elements with theire ids
}
}