Click here to Skip to main content
12,394,552 members (69,707 online)
Rate this:
 
Please Sign up or sign in to vote.
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 3: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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2016
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