使用c#登录instagram后如何导航到新网址

时间:2015-07-12 16:41:58

标签: c# login instagram

您好我正在尝试构建一个允许使用c#

登录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");
        }
    }
}

}

1 个答案:

答案 0 :(得分:0)

您需要保留会话Cookie。最好使用一些允许您连接到instagram的组件,例如:https://www.nuget.org/packages/InstaSharp/