|
-
Jan 3rd, 2010, 10:42 PM
#1
Thread Starter
Lively Member
Grab / display parts of text in source (webbrowser)
Hi, I'm trying to grab or display certain parts of text from a websites source code from my web browser control on my form.
I've tryed displaying the whole source code into a textbox (a lot of lines) then trying to retrieve the text I need but with no luck.
The part of the source looks like this:
Code:
<!-- MAIN PAGE AREA -->
<div class="tripleColumn" id="contentGrid">
<div class="modCopy textContent">
<h1 class="petrol">Message Retention</h1>
<br />
<!-- MAIN PAGE AREA -->
<table border="1" bordercolor="#000000" cellspacing="0" cellpadding="1" width="375">
<tr>
<td align="left" valign="middle" width="75"><b>Time/Date:</b></td>
<td align="left" valign="middle" width="300">2010-01-03 18:55</Td>
</tr>
<tr>
<td align="left" valign="middle" width="75"><b>Message:</b></td>
<td align="left" valign="middle" width="300">70:Jan 3 18:55 MESSAGE IS HERE</Td>
</tr>
</table>
<br />
<table border="1" bordercolor="#000000" cellspacing="0" cellpadding="1" width="375">
<tr>
<td align="left" valign="middle" width="75"><b>Time/Date:</b></td>
<td align="left" valign="middle" width="300">2010-01-03 18:28</Td>
</tr>
<tr>
<td align="left" valign="middle" width="75"><b>Message:</b></td>
<td align="left" valign="middle" width="300">69:Jan 3 18:28 MESSAGE IS HERE</Td>
</tr>
</table>
<br />
</div>
</div>
I've included and colored part of the source code (only the part I want text from) which includes 2 messages with their relative information which i've coloured (there will be more than 2 messages, but look the same).
This is a pager service, displays messages from pager with the info i've provided, is there anyway to grab the text from the relative tags and repeat for each one. For example, this might work:
Code:
<td align="left" valign="middle" width="75">
to
that will grab all the time and date, if another way please share, thanks.
Is there a easier way?
Only reason is because if the text has changed (which i add it all to a textbox for the user to read) I can play a sound or notify in the textbox changed event.
-
Jan 4th, 2010, 09:32 AM
#2
Hyperactive Member
Re: Grab / display parts of text in source (webbrowser)
It is quite easy to get the inner text of the elements in the table rows. If your web browser control is called WebBrowser1, for example, you can access the HTML document using WebBrowser1.document property.
So,
Code:
Dim htDoc as HTMLDocument = WebBrowser1.document
gives you the entire document.
Now, you need to extract the elements with the tag name "tr". This can be done with HTMLDocument.GetElementsByTagName(). Each of those returned elements have a property called InnerText that contains the text inside the tags (excluding all the formatting information etc).
Eg. The following code will loop through the elements with the tag name "tr" and display their inner text in message boxes.
Code:
Dim elemColl As HtmlElementCollection = htdoc.GetElementsByTagName("tr")
For Each elem As HtmlElement In elemColl
MsgBox(elem.InnerText)
Next
Hope this helps.
Runesmith
The key to getting the right answer is asking the right question
I just realized: good health is merely the slowest possible rate at which one can die
-
Jan 4th, 2010, 01:38 PM
#3
Thread Starter
Lively Member
Re: Grab / display parts of text in source (webbrowser)
 Originally Posted by Runesmith
It is quite easy to get the inner text of the elements in the table rows. If your web browser control is called WebBrowser1, for example, you can access the HTML document using WebBrowser1.document property.
So,
Code:
Dim htDoc as HTMLDocument = WebBrowser1.document
gives you the entire document.
Now, you need to extract the elements with the tag name "tr". This can be done with HTMLDocument.GetElementsByTagName(). Each of those returned elements have a property called InnerText that contains the text inside the tags (excluding all the formatting information etc).
Eg. The following code will loop through the elements with the tag name "tr" and display their inner text in message boxes.
Code:
Dim elemColl As HtmlElementCollection = htdoc.GetElementsByTagName("tr")
For Each elem As HtmlElement In elemColl
MsgBox(elem.InnerText)
Next
Hope this helps.
Wow, incredible, so easy.
Thanks so much.
-
Jan 4th, 2010, 01:52 PM
#4
Thread Starter
Lively Member
Re: Grab / display parts of text in source (webbrowser)
One last thing.
It takes about 25 seconds to display all the text into a textbox. I don't mind it taking that long to load it at start, but it will take 25 secs everytime I refresh it or load it, too long.
Is there a faster or better way of displaying the text? Or somhow searching if the text in the table has changed ( got bigger)
It also freazes when doing it, and it just also crashed when I reloaded it into textbox, come up with a long message.
Last edited by meight; Jan 4th, 2010 at 02:12 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|