2015-07-12 20 views
0

嗨,我是試圖建立一個應用程序,允許登錄使用C#如何定位到新的URL登錄後使用C#

當我運行我的應用程序,並登錄到Instagram的到Instagram的,我需要重定向固定頁面 未經我任何反應

這裏是我的代碼:

{ 
public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     HtmlDocument doc = web.Document; 
     HtmlElement username = doc.GetElementById("id_username"); 
     HtmlElement password = doc.GetElementById("id_password"); 

     username.SetAttribute("value", "test"); 
     password.SetAttribute("value", "test"); 

     StringBuilder sb = new StringBuilder(); 

     foreach (HtmlElement elm in web.Document.All) 
      if (elm.GetAttribute("value") == "Log in") 
      { 
       sb.Append(elm.InnerHtml); 

       Thread.Sleep(3000); 
       elm.InvokeMember("click"); 
       web.Navigate(@"https://instagram.com/accounts/edit/"); // it navigate me but required to login again 


      } 



    } 

    private void web_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) 
    { 
     if (web.Document.Url.AbsoluteUri.Equals(@"https://instagram.com")) 
     { 
      MessageBox.Show("logged in"); 
     } 
    } 
} 

}

回答

0

你需要保持會話cookie。更好地使用一些組件,讓你連接到instagram,如:https://www.nuget.org/packages/InstaSharp/

+0

你可以提供如何使用c#中的webBrowser組件cookie的建議@Artur Malendowicz – m1m6

相關問題