Results 1 to 8 of 8

Thread: VBA: Get value by Class name
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Sep 2014
    Posts
    629
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default VBA: Get value by Class name

    Hello, trying to get the price from the website:

    https://www.tesco.com/groceries/en-G...ucts/303105747

    So would return 3.00

    Any ideas, this is my attempt?

    Thanks in advance!

    Code:
    Sub WebData()
        Dim http As New XMLHTTP60, html As New HTMLDocument
        Dim source As Object
    
    
        With http
            .Open "GET", "https://www.tesco.com/groceries/en-GB/products/303105747", False
            .send
            html.body.innerHTML = .responseText
        End With
        For Each source In html.getElementsByClassName("data-auto")
            x = x + 1: Cells(x, 1) = source.getAttribute("value")
    
    
        Next source
    End Sub

  2. #2
    Board Regular
    Join Date
    Sep 2014
    Posts
    629
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA: Get value by Class name

    Any ideas please?

  3. #3
    Board Regular
    Join Date
    Sep 2014
    Posts
    629
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA: Get value by Class name

    Any ideas thanks!

  4. #4
    Board Regular Kyle123's Avatar
    Join Date
    Jan 2012
    Location
    Leeds, UK
    Posts
    2,642
    Post Thanks / Like
    Mentioned
    10 Post(s)
    Tagged
    2 Thread(s)

    Default Re: VBA: Get value by Class name

    Like this:
    Code:
        Dim http As New XMLHTTP60, html As New HTMLDocument
        Dim source As Object
    
    
        With http
            .Open "GET", "https://www.tesco.com/groceries/en-GB/products/303105747", False
            .send
            html.body.innerHTML = .responseText
        End With
    
        MsgBox html.querySelector(".price-details--wrapper .value").innerText

  5. #5
    Board Regular
    Join Date
    Sep 2014
    Posts
    629
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA: Get value by Class name

    Thanks, can you let me know how I would put this into a cell?

  6. #6
    Board Regular Kyle123's Avatar
    Join Date
    Jan 2012
    Location
    Leeds, UK
    Posts
    2,642
    Post Thanks / Like
    Mentioned
    10 Post(s)
    Tagged
    2 Thread(s)

    Default Re: VBA: Get value by Class name

    Code:
    SomeWorksheet.Range("A1").value2 = html.querySelector(".price-details--wrapper .value").innerText

  7. #7
    Board Regular
    Join Date
    Sep 2014
    Posts
    629
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA: Get value by Class name

    That is great thanks and works.

    I have 1 further question:

    How would I loop through URLs, I am thinking

    For x = LBound(urls) To UBound(urls)

    Sheets("Sheet1").Cells(Sheets("Sheet1").Rows.Count, 1).End(xlUp).Offset(1).Resize(UBound(dogLinks), 17).Value2 = dogLinks
    Next x
    .Open "GET", url, False
    .send
    html.body.innerHTML = .responseText
    End With

  8. #8
    Board Regular
    Join Date
    Sep 2014
    Posts
    629
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA: Get value by Class name

    Any ideas here please on how to add the loop?

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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