Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want make a class whit method wich used for read a string from a web page and return method but I cant write this.:-(





foe example:

webparsing reader=new webparsing();
string a=reader.read();
C#
<pre>namespace WindowsFormsApplication6
{
    class webparsing
    {

        private System.Windows.Forms.WebBrowser webBrowser1;
        private void initial()
        {
            this.webBrowser1 = new System.Windows.Forms.WebBrowser();
            webBrowser1.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
            webBrowser1.Navigate("http:\\google.com");
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            //do any
        }

        public string read()
        {
            initial();
            
            return webBrowser1.Document.GetElementById("lst-ib").InnerText;
        }


What I have tried:

I wand read a text from a text box and return but don't wait for web page complete.how to write this code?
Posted
Updated 9-Nov-17 21:55pm
v2
Comments
mosifallah 10-Nov-17 3:55am    
oh tanks it is very good ....thanks thanks
Karthik_Mahalingam 10-Nov-17 4:00am    
welcome

it is answer thank a lot of
Karthik Bangalore 

  bool IsReady;
 void Go()
 {
     IsReady = false;
     brw.Navigate("url");
     do
     {
         Thread.Sleep(10);
         Application.DoEvents();
     } while (!IsReady);
 }

void brw_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
 {
     IsReady = true;
 }
 
Share this answer
 
v2
When the load completes, you get the DocumentCompleted event - or you would if that code compiled, which it won't. You get a "Unrecognized escape sequence" error from the compiler, so no executable is generated. Start by changing it to this:
webBrowser1.Navigate("listname.html");
and see if that helps - it probably won't, unless your file is in the executable directory, but that's your problem, not mine! :laugh:

So even when you fix that, and it finds the file, the load won't happen instantaneously: you need to get your element in the handler, not an unrelated method.
In the handler, you can set the textbox using the SetAttribute method:
HtmlDocument doc = webBrowser1.Document;
doc.GetElementById("myId").SetAttribute("Value", "Text I want in the text box");
 
Share this 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