Click here to Skip to main content
11,790,613 members (61,100 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: WebForms VB.NET Browser , +
How do I get to add all links within a particular div from vb browser?

I'm trying to get all links from the div class linksmain.


<div class="linksmain">
<a href="">Image</a>
<a href="">Image</a>
<a href="">Image</a>

So far I've got this..


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
End If
Posted 30-Apr-13 3:31am

1 solution

Rate this: bad
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;
         } catch (e) { alert('Error enumerating children. (' + e.Message + ')'); }
         return children;

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

  Print Answers RSS
0 OriginalGriff 1,154
1 Maciej Los 825
2 KrunalRohit 686
3 ppolymorphe 660
4 CPallini 621

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