extract text

Discussion in 'Visual Basic .NET' started by astradamasta, Nov 29, 2008.

  1. astradamasta

    astradamasta Registered Member

    Joined:
    Nov 24, 2008
    Messages:
    56
    Likes Received:
    8
    i have been programming in vb6 for about 4 years. i'm changing over to vb 2008. I'm trying to extract user names from my webbrowser...i have been trying to use the getelementbyid and i havent had any success..here is a part of the html code:

    href="/user/Justin" >Justin</a></span></div>
    href="/user/Shannon" >Shannon</a></span></div>
    href="/user/Jessica" >Jessica</a></span></div>
    href="/user/Johnny" >johnny</a></span></div>

    how could i extract these usernames?? i want to extract justin, shannon, jessica, and johnny. thanks in advance
     
  2. lamlam

    lamlam Junior Member

    Joined:
    Oct 25, 2008
    Messages:
    134
    Likes Received:
    854
    Occupation:
    What do you think?
    Location:
    In my home...
    Put that into TextBox1 and add a ListBox, then try this:

    Code:
     
    Dim Lines() As String = TextBox1.Text.Split(vbCrLf)
            For Each Line As String In Lines
                Dim fullstring As String = Line
                Dim split1() As String
                Dim split2() As String
                split1 = fullstring.Split("/")
                split2 = split1(2).Split(Chr(34))
                ListBox1.Items.Add(split2(0))
            Next
    
     
    • Thanks Thanks x 1
    Last edited: Dec 1, 2008
  3. astradamasta

    astradamasta Registered Member

    Joined:
    Nov 24, 2008
    Messages:
    56
    Likes Received:
    8
    thanks the code works great, you're the best
     
  4. Skank

    Skank Newbie

    Joined:
    Nov 3, 2009
    Messages:
    47
    Likes Received:
    8
    A more efficient way of doing it is to do is straight from the web browser.

    Try:

    Dim lnk as htmlelement
    For each lnk in webbrowser1.document.getelementbytype("a")
    Listbox1.items.add(lnk.innertext)
    Next

    Your listbox would then contain:

    Justin
    Shannon
    Jessica
    Johnny

    You're probably scanning Youtube or a similar site for usernames right?