Click here to Skip to main content
15,911,142 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hi, i am trying to post on different websites using c#. I am doing it through a web Browser( the one already in .Net). The code i have done so far is below, in this i am successfully opening facebook and when i click on button_2 it automatically fills the login form and i am successfully logged in then. This means i can do it for other sites as well by doing a little changes. Now the problem here is i want to post some data to different sites, like a link or something, and when i am logged in successfully like in did in the code below what lets say a page opens and in that page i have to fill some data or that link the fields they ask. How to do that to proceed further to fill other form fields? and when i have done that i want to save that final result from that site to a text file?
kindly tell me how to do that? or any useful links.
Regards.


C#
private void button1_Click(object sender, EventArgs e)
        {

            webBrowserCtl.Navigate("https://login.facebook.com/login.php?login_attempt=1");
            webBrowserCtl.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
  
        }
        void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            string s = webBrowser1.DocumentText;
           // btnLogin.Enabled = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            HtmlElement ele = webBrowserCtl.Document.GetElementById("email");
            if (ele != null)
                ele.InnerText = "email here";

            ele = webBrowserCtl.Document.GetElementById("pass");
            if (ele != null)
                ele.InnerText = "password here";

            ele = webBrowserCtl.Document.GetElementById("Login");
            if (ele != null)
                ele.InvokeMember("click");
        }
Posted
Updated 14-Aug-12 3:26am
v2
Comments
[no name] 14-Aug-12 9:27am    
"fill other form fields"... if you already know how to do this then why are you asking?
Member 9357064 14-Aug-12 9:31am    
no i am now asking is that in return if the webpage returns some value how to save it to a text file that keeps its url other data.
[no name] 14-Aug-12 9:35am    
"How to do that to proceed further to fill other form fields?" How is that not something that you are asking? You already know this so why are you asking? Take the data and save it to a file... what exactly are you having trouble with? What have you tried? Where is the code that demonstrates the issue?
Member 9357064 14-Aug-12 9:42am    
look this is done till now and it logs me in to the FB. but now i have to do 2 more things:
1: I need to login to multiple sites not just the example of what i gave, because this does not logins me to gmail or one of my sites. This is one issue.
2: when i post to a page like if i post an ad on a site then i want the bot to automatically save the uri of the page like when the ad has been posted(the uri of page after submission), it must save it to a text file automatically.
[no name] 14-Aug-12 9:50am    
And so? It's not logging you onto gmail because each webpage is different! You have to write code for each one that you want to log into.

1 solution

Hi
Why don't you use System.Net.WebRequest for this purpose. please have a look at this :
http://msdn.microsoft.com/en-us/library/debx8sh9.aspx

Regards
Pawan
 
Share this answer
 
Comments
Abdul Quader Mamun 14-Aug-12 9:39am    
easy Answer!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900