Click here to Skip to main content
13,259,771 members (47,228 online)
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();
string a=reader.read();
<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 8-Nov-17 23:27pm
Updated 9-Nov-17 22:55pm
v2
Comments
mosifallah 10-Nov-17 3:55am
   
oh tanks it is very good ....thanks thanks
Karthik Bangalore 10-Nov-17 4:00am
   
welcome
Rate this: bad
 
good
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:
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");
  Permalink  
Rate this: bad
 
good
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;
        brw.Navigate("url");
        do
        {
            Thread.Sleep(10);
            Application.DoEvents();
        } while (!IsReady);
    }
 
   void brw_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        IsReady = true;
    }
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web03 | 2.8.171114.1 | Last Updated 10 Nov 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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