-
Sep 24th, 2015, 05:17 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Need help with finding html elements
Hello,
I have a WebBrowser, I'm tying to get text of some elements, that has inner elements. The hierarchy seems like:
HTML Code:
<tr class="" id="trItem33998" spry:select="selectedRow" spry:hover="hoverRow">
<td style="cursor:pointer">
<span>A4 TECH KB-2150D Q-TR MULTIMEDYA USB SİYAH SET</span>
</td>
<td>
<span>18</span>
</td>
...
<tr>
There are many enumerated rows like this and I need to get all text in span tags in that table. All ids start with trItem. How can I do this using Visual Basic 2013?
-
Sep 24th, 2015, 11:37 PM
#2
Re: Need help with finding html elements
Hi,
This can be easily achieved by using the GetElementsByTagName Method of the HTMLDocument which is exposed by the WebBrowser control. You can then use various methods to iterate the returned elements to obtain your data. Have a play with this example:-
vb.net Code:
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then For Each parentElement As HtmlElement In WebBrowser1.Document.GetElementsByTagName("tr").Cast(Of HtmlElement).Where(Function(x) x.GetAttribute("id").StartsWith("trItem")) For Each spanElement As HtmlElement In parentElement.GetElementsByTagName("span") MsgBox(spanElement.InnerText) Next Next End If End Sub
Hope that helps.
Cheers,
Ian
-
Sep 25th, 2015, 01:00 AM
#3
Thread Starter
Addicted Member
Re: Need help with finding html elements
Thanks for the help. I tested and it worked fine. But now I have another problem. The web page is written in aspx and your code doesn't give me the code I see in browser panel "inspect element". I'm just able to get elemets of the source of the page. I don't know why it differs. Any ideas?
-
Sep 25th, 2015, 02:00 AM
#4
Re: Need help with finding html elements
Nope and nor do I know what you mean!
It does not matter whether it’s an ASPX page or any other type of web page it is still just basic HTML Tags. So, what do you see when you select Inspect Element on that web page?
Ian
-
Sep 25th, 2015, 02:36 AM
#5
Thread Starter
Addicted Member
Re: Need help with finding html elements
It shows this:
... and they aren't shown in page source.
-
Sep 25th, 2015, 02:53 AM
#6
Re: Need help with finding html elements
Hi,
I think you are going to need to do some research on this subject and then think about how this affects what it is that you are trying to do. Have a start with this:-
Is the HTML is View Source different from the HTML in Inspect Element?
Good Luck.
Cheers,
Ian
-
Sep 25th, 2015, 03:08 AM
#7
Thread Starter
Addicted Member
Re: Need help with finding html elements
ok. thanks for helping.
Can
Tags for this Thread
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
|