Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WebForms VB.NET Browser , +
How do I get vb.net to add all links within a particular div from vb browser?
 
I'm trying to get all links from the div class linksmain.
 
E.g.
 
<div class="linksmain">
<a href="http://www.image1.com">Image</a>
<a href="http://www.image2.com">Image</a>
<a href="http://www.image3.com">Image</a>
</div>
 

So far I've got this..
 
Code:
 
Dim web As New WebBrowser
 
If web.ReadyState = WebBrowserReadyState.Complete Then
    Dim allelements As HtmlElementCollection = web.Document.All
 
    For Each webpageelement As HtmlElement In allelements
 
        ListBox1.Items.Add(webpageelement.GetAttribute("class"))
 
    Next
End If
Posted 30-Apr-13 4:31am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

That's client side stuff - you would use javascript for that. Here's a javascript function that will return an array containing the IDs of all the elements (that have IDs) in the chosen div. You'll have to enumerate them and decide which children you need to use. This means that all the items you are looking for must have IDs, of course.
 
 
   function GetAllChildrenIn(parentElement) {
            var children = new Array();
            var numFound = 0;
            try {
                var obj = document.getElementById(parentElement);
                var numChildren = obj.childNodes.length;
            } catch (e) {
                alert('Error setting vars. (' + e.Message + ')'); }
 
            try {
                for (var count = 0; count < numChildren; count++) {
                    if (obj.childNodes[count].id) {
                        children[numFound] = obj.childNodes[count].id;
                        numFound++;
                    }
                }
            } catch (e) { alert('Error enumerating children. (' + e.Message + ')'); }
 
            return children;
        }
 
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 390
1 Sergey Alexandrovich Kryukov 329
2 Afzaal Ahmad Zeeshan 244
3 BillWoodruff 210
4 Maciej Los 192
0 OriginalGriff 5,560
1 DamithSL 4,476
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2014
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