im using this code to login to site :
string url = "http://mysite.com/login";
string username = "someUserName";
string password = "somePassword";
string commit = "Sign+In";
private void Login()
{
WebBrowser b = new WebBrowser();
b.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(b_DocumentCompleted);
b.Navigate(url);
}
private void b_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser b = sender as WebBrowser;
string response = b.DocumentText;
int index = response.IndexOf("authenticity_token");
int startIndex = index + 41;
string authenticityToken = response.Substring(startIndex, 40);
b.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(b_DocumentCompleted);
b.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(b_DocumentCompleted2);
string postData = string.Format("authenticity_token={2}&session[username_or_email]={0}&session[password]={1}&commit={3}", username, password, authenticityToken, commit);
ASCIIEncoding enc = new ASCIIEncoding();
b.Navigate("https://twitter.com/sessions", "", enc.GetBytes(postData), "Content-Type: application/x-www-form-urlencoded\r\n");
}
private void b_DocumentCompleted2(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser b = sender as WebBrowser;
string response = b.DocumentText;
if (response.Contains("Sign out"))
{
MessageBox.Show("Login Successful");
}
}
after login successful im trying to extract data from (userinfo.php) about user like name,age with htmlagilitypack (http://htmlagilitypack.codeplex.com)
using this code :
to get every url in (userinfo.php)
HtmlAgilityPack.HtmlWeb web = new HtmlWeb();
HtmlAgilityPack.HtmlDocument doc = web.Load("http://mysite.com/userinfo.php");
foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href"])
{
HtmlAttribute att = link["href"];
att.Value = FixLink(att);
MessageBox.Show(""+att.Value);
}
it doesn't work ?? i don't know why ???
note : (userinfo.php) containe urls and its restricted page (but i loging successful first !!!!)
