1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Get URL image by Class

Discussion in 'Visual Basic .NET' started by dragosdydy, Apr 23, 2013.

  1. dragosdydy

    dragosdydy Junior Member

    Joined:
    Jan 23, 2012
    Messages:
    116
    Likes Received:
    49
    Location:
    Italy
    Hi guys, I'm working on one of my projects and i encountered an issue. I don't know how to get a link for one image searching by it's class.
    The link for the image is different for every URL but the image class is always the same.
    The HTML code is something like that:

    HTML:
    <img id="251" alt="random_name" src="https://LinkOfTheImage.jpg" class="Picture img">

    I think i must use the GetElementByClass but i dont how to get the src attribute.
    Do you guys know how can i get the link of the image for every URL i search? Thanks.
     
  2. innozemec

    innozemec Jr. VIP Jr. VIP

    Joined:
    Aug 19, 2011
    Messages:
    5,289
    Likes Received:
    1,799
    Location:
    www.Indexification.com
    Home Page:
    I did it this way for the href tag of links.. tweak it for img and src..

    Code:
            Dim nodes = doc.DocumentNode.SelectNodes("//a[@href]")
            For Each node As HtmlNode In nodes
                Dim att As HtmlAttribute = node.Attributes("href")
                If String_Contains(att.Value, "registr") Then
                    ForReturn = Trim(att.Value)
                End If
            Next
    
     
  3. dragosdydy

    dragosdydy Junior Member

    Joined:
    Jan 23, 2012
    Messages:
    116
    Likes Received:
    49
    Location:
    Italy
    Thanks for the reply. Have a nice day.