Click here to Skip to main content
14,384,408 members
Rate this:
Please Sign up or sign in to vote.
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();
<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);

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

        public string read()
            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 to write this code?
Updated 9-Nov-17 22:55pm
mosifallah 10-Nov-17 3:55am
oh tanks it is very good ....thanks thanks
Karthik_Mahalingam 10-Nov-17 4:00am
Rate this:
Please Sign up or sign in to vote.

Solution 1

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:
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");
Rate this:
Please Sign up or sign in to vote.

Solution 2

it is answer thank a lot of
Karthik Bangalore 

  bool IsReady;
 void Go()
     IsReady = false;
     } while (!IsReady);

void brw_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
     IsReady = true;

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100