Web query - pull only specific data from a HTML page
Hi,

I'm trying to pull a piece of data from a webpage. Yes, I can build a web query no problem and it pulls the data into the spreadsheet fine, but I want just a single piece of data from the page and not the entire website. I'm aware that you can select what data you want from the page, but most of the time it doesn't provide you with the option to choose exactly what you want and loads all the rest of the 'rubbish' on the page.

Example
I want to pull just a price of a product from a page. I don't want anything else from this page. Within the HTML code, the price is contained like this:
</span>
                <span class="price-including-tax">
                    <span class="label">Incl. VAT:</span>
                    <span class="price" id="price-including-tax-9">8.22                    </span>
                </span>
                        
        </div>

Is there a way to to modify the URL I use to create the web query so that it only picks up this single item?

Many thanks for your help.

Rob
July 3rd, 2013 7:57am

Load the returned file into a string variable, and use string manipulation to find the value between

<span class="price" id="price-including-tax-9">

and the following span

</span>


Free Windows Admin Tool Kit Click here and download it now
July 3rd, 2013 10:42am

Hi Bernie,

Thanks for that. Excuse my question - I'm not a developer - but can I perform this action (string manipulation) or would I need to do in another programme?

thanks,

Rob
July 4th, 2013 5:52am

     

For example, if your site is microsoft.com, and you want the 20 characters after "price-including-tax-9" placed into cell A1:

 

Sub ReadSite()

    Dim ie As Object
    Dim sResult As String
    Dim sFinal As String
    Dim dtTimer As Date
    Dim lAddTime As Long
    Dim lngPrice As Long
    Dim strFind As String
    Dim iCharCount As Integer

    Const lREADYSTATE_COMPLETE As Long = 4

    Set ie = CreateObject("InternetExplorer.Application")
    ie.silent = True
    ie.navigate "http://www.microsoft.com"

    dtTimer = Now
    lAddTime = TimeValue("00:00:20")

    Do Until ie.readystate = lREADYSTATE_COMPLETE And Not ie.busy
        DoEvents
        If dtTimer + lAddTime > Now Then Exit Do
    Loop

    sResult = ie.document.body.innertext
    MsgBox sResult
    strFind = "price-including-tax-9"
    iCharCount = 20
    lngPrice = InStr(1, sResult, strFind) + Len(strFind)

    sFinal = Mid(sResult, lngPrice, iCharCount)
    MsgBox sFinal
    Sheets("Sheet1").Range("A1") = sFinal
    

    ie.Quit
    Set ie = Nothing

End Sub

Free Windows Admin Tool Kit Click here and download it now
July 4th, 2013 12:09pm

Many thanks!
July 4th, 2013 7:04pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics