dcsimg
Results 1 to 8 of 8

Thread: [RESOLVED] Get element by class

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    23

    Resolved [RESOLVED] Get element by class

    Well,
    I have a WebBrowser1
    Code:
      <div class="player_wrap">
        <div id="line52174426_101209104_93164364_268" class="playline"><div>
    I need to get id param to textbox1.text
    But 52174426_101209104_93164364_268 - random numbers.
    How to get id by class?
    Last edited by FlashPADONAK; Mar 13th, 2011 at 07:12 AM.

  2. #2
    Addicted Member
    Join Date
    Jan 2011
    Posts
    132

    Re: Get element by class

    Im quite new to VB, But i think you might be able to use getElementsByTagName

    Theres some tutorials on Youtube for it.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    23

    Re: Get element by class

    Barrabutus, well...
    In vb
    Code:
            Dim PageElement As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
            For Each CurElement As HtmlElement In PageElement
                TextBox1.Text = TextBox1.Text + CurElement.GetAttribute("value") + Environment.NewLine
            Next
    I get an array to TextBox1:
    Code:
    logout
    1
    site.com
    random
    http://cs4601.site.com/u67118412/audio/9fa3ddef8f4e.mp3,250
    logout
    1
    site.com
    random
    http://cs4601.site.com/u67118412/audio/9fa3ddef8f4e.mp3,250
    But I'm need only that: http://cs4601.site.com/u67118412/audio/9fa3ddef8f4e.mp3,250

  4. #4
    Addicted Member
    Join Date
    Jan 2011
    Posts
    132

    Re: Get element by class

    What is the web address please, I can see if I can get it to output what you need

    Regards Barra.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    23

    Re: Get element by class

    This is site vkontakte.ru (vk.com)
    I want to release download a music
    example (http://vk.com/wall93164364_271)

  6. #6
    Addicted Member
    Join Date
    Jan 2011
    Posts
    132

    Re: Get element by class

    I have been trying to get this to work for a little while now because i was finding problems getting Div by class name but i got it to work.

    Code:
        Dim PageElement As HtmlElementCollection = Form2.WebBrowser1.Document.GetElementsByTagName("div")
            For Each CurElement As HtmlElement In PageElement
               'ListBox1.Items.Add(CurElement.GetAttribute("className").ToString())
                If (CurElement.GetAttribute("className") = "playline") Then
    
                    TextBox1.Text = CurElement.GetAttribute("id")
                End If
    
    
            Next
    This results in line93164364_99229399_93164364_271
    being displayed in the textbox.

    Is this what you was trying to achieve?

    Regards Barra.

  7. #7
    Addicted Member
    Join Date
    Jan 2011
    Posts
    132

    Re: Get element by class

    Do you need the URL from the page or the Random Number list

    In your first post you asked to
    " I need to get id param to textbox1.text
    But 52174426_101209104_93164364_268 - random numbers."

    Then further on you said
    "But I'm need only that: http://cs4601.site.com/u67118412/audio/9fa3ddef8f4e.mp3,250"

    So which do you need? the URL or numbers or both ?

    regards Barra.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    23

    Re: Get element by class

    Barrabutus, thanks! all right)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width