Click here to Skip to main content
15,921,841 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day,

My problem is I need to read the text from webbrowser
then when I click on button split the text in web browse and put this
text split in textbox
Posted
Updated 19-Feb-11 11:53am
v2
Comments
Sergey Alexandrovich Kryukov 19-Feb-11 17:54pm    
Your statement sounds like a pseudo-code. Make it into a code, show it and finally -- tell us what's your question.
--SA
Albin Abel 19-Feb-11 18:05pm    
Sorry i don't have vb.net in my machine, so I given the example in c#. However it is not hard to convert vb.net I hope. Also pls explain what you mean by split i.e how you want the split. The Document variable in my example have property to get the element collection. You can iterate through the element collection an get the each element html also.

If my answer is not relevant tell me, I ll delete it from here

Hi,

If you are talking about extracting the content in the webbrowser control then here is the code, otherwise excuse and explain a bit more.

I am using a richtextbox in this example. This example here shows a walk thorugh all html elements or get a html element by tag (even can get the element by ID as well). Then get each element's details. That way you can split the html into element by element. If you want split any string use the split function

C#
private void button1_Click(object sender, EventArgs e)
{
   HtmlDocument doc=  (HtmlDocument)webBrowser1.Document;
   richTextBox1.AppendText("<html>");

    //Get elements by tag.
   HtmlElementCollection coll1= doc.GetElementsByTagName("head");

   //if want to walk through all elements then
   HtmlElementCollection coll2 = doc.All;
   foreach (HtmlElement element in coll1)
   {
       //Here can get elements properties like
       //(just for example i am declaring variables inside the loop, it is not good way)

       string name=element.Name;
       string id = element.Id;
       string innerHtml = element.InnerHtml;
       string outerHtml = element.OuterHtml;


       //Navigate around
       HtmlElement firstChild = element.FirstChild;
       HtmlElement nextSibling = element.NextSibling;
       HtmlElementCollection children = element.Children;



       richTextBox1.AppendText(element.OuterHtml);
   }
   richTextBox1.AppendText(doc.Body.OuterHtml);
   richTextBox1.AppendText("</html>");
}
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 19-Feb-11 20:34pm    
Most likely, this is right to the point, not "Split", my 5.
--SA
Albin Abel 19-Feb-11 22:07pm    
thanks
Espen Harlinn 20-Feb-11 9:37am    
Good reply, my 5
For the second part take a look at String.Split() on MSDN.

I assume that you can do the first part, since that is a very common thing to do and so you will already have found the answer with an internet search.
 
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