How do I Extrat The Value of the ID Element into Excel?

drmingle

Board Regular
Joined
Oct 5, 2009
Messages
229
HTML:
<div id="resultStats">About 2,660,000,000 results<nobr>  (0.20 seconds) </nobr></div>

This is coming from the source of Google's home page (right under the search toolbar).

I essentially want to pull down the phrase "About 2,660,000,000 results".

Up to this point I have been using Excel's web query and recording it with a macro.

Any help would be appreciated...
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hotpepper... thanks for the quick response.


However, I am actually trying to download this information from the internet, not really parse anything out.
 
Upvote 0
I can think you can do that you would either need to automate IE or use XMLHTTP.

If you look at the first part of the code in poolhall's link it shows you how to automate IE.

However you don't need to save the source code to a text file to get what you want.

You can just add some code after Set objDoc = ie.Document.
Rich (BB code):
Option Explicit
 
Sub GetGoogleResultsStats()
Dim ie As Object, objDoc As Object, f As Object, fs As Object
Dim NoResults As String
Const strURL As String = "http://www.google.co.uk/#sclient=ps...q=f&aqi=g5&aql=&oq=&pbx=1&fp=8d5bc33c08a07e29"
 
    Set ie = CreateObject("internetexplorer.application")
 
    ie.Navigate strURL
    'Wait for page to load!
    Do
        If ie.ReadyState = 4 Then
            ie.Visible = False
            Exit Do
        Else
            DoEvents
        End If
    Loop
 
    Set objDoc = ie.Document
 
    NoResults = objDoc.getelementByID("resultStats").InnerText
 
    MsgBox NoResults

    Set objDoc = Nothing

    Set ie = Nothing

End Sub

Obviously replace the URL with a real one - I just copied what was in the address bar after searching for 'something'.:)
 
Upvote 0
Norie:

Thank you for the code. This is what I am looking for...

I am getting an "error code 91" on the line:

Code:
NoResults = objDoc.getElementById("resultStats").innerText

Is there a DLL that I should activate through the reference library?
 
Upvote 0
That error has nothing to do with a DLL.

Did you substitute a valid URL for the one in the code?

The basic test of validity would be that the URL actually returns the result stats on the page.

If it doesn't then the code won't find an element with the ID 'resultStats', so there is no object to work with.
 
Upvote 0
I did put a proper URL in the code.

No results because it errored out (error 91).

Excel prompted me to debug.
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,459
Members
452,915
Latest member
hannnahheileen

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