Understanding class or attribute in html

jamescooper

Well-known Member
Joined
Sep 8, 2014
Messages
840
Hello,

Bit of a novice on pulling data from the web.

The 3 lines in bold below work. But when I try to pull another element, ret(4), the code isn't working.

How do I work out whether it is a class or attribute?

Many thanks.

Code:
Private Function getprices(ByVal URL As String) As Variant


    Dim source As Object
    Dim http As New XMLHTTP60, html As New HTMLDocument
    Dim ret(1 To 4) As String
    
    With http
        .Open "GET", URL, False
        .send
        html.body.innerHTML = .responseText
    End With

[B]    ret(1) = html.querySelector(".price-details--wrapper .value").innerText[/B]
[B]    ret(2) = html.querySelector(".price-per-quantity-weight .value").innerText[/B]
[B]    ret(3) = html.querySelector(".price-per-quantity-weight .weight").innerText[/B]
'   ret(4) = html.querySelector(".promotions-wrapper hidden-medium .offer-text").innerText

getprices = ret


End Function
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
In HTML class is an attribute, as are id, src etc.

What element(s) are you trying to select with this?
Code:
html.querySelector(".promotions-wrapper hidden-medium .offer-text").innerText
 
Upvote 0
What you have there is an element with multiple classes.

You could try using '.offer-text' on it's own, which worked for me, but if you want to be more specific you can try this.
Code:
  ret(4) = html.querySelector(".promotions-wrapper.hidden-small.hidden-medium-small-only .offer-text").innerText
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top