Solved

Retrieve Search Engine Results

Posted on 2004-03-26
4
276 Views
Last Modified: 2008-03-06
Is there a way using VB6 to extract information from a serach engine.

I run a number of website that i currently manually have to check various page ranks and such on.

for instance i may run the query link: http://www.direct-marketing-lists.co.uk on google

what i need to do is extract the count result of 8 from the top right of the screen.

I also wish to do this with a number of different search engines

any ideas?
0
Comment
Question by:Marcusw
  • 2
4 Comments
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 10686953
You can use an HTMLDocument object with a hard-coded search-query link to retrieve the HTML. Then simply parse it. Example of getting the first 8 results from Google below.

Project -> References -> "Microsoft HTML Object Library"

Form1:
-------------------

Private Const sURLGoogle As String = "http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=REPLACEME&btnG=Google+Search"
Private Sub Form_Load()
    Dim sResults As Collection, iLoop As Integer
    Call SearchGoogle("example", sResults)
    For iLoop = 1 To 8
        MsgBox sResults(iLoop)
    Next iLoop
End Sub
Private Sub SearchGoogle(ByVal sQuery As String, ByRef sResults As Collection)
    Dim hDoc1 As New HTMLDocument, hDoc2 As New HTMLDocument
    Dim hCol1 As IHTMLElementCollection, objTemp As Object
    Set hDoc1 = hDoc2.createDocumentFromUrl(Replace(sURLGoogle, "REPLACEME", sQuery), "null")
    Do Until hDoc1.readyState = "complete"
        DoEvents
    Loop
    Set hCol1 = hDoc1.All.tags("p")
    Set sResults = New Collection
    For Each objTemp In hCol1
        If sResults.Count <> 8 Then
            Call sResults.Add(objTemp.outerText)
        End If
    Next objTemp
End Sub


0
 

Author Comment

by:Marcusw
ID: 10687034
i think you have misunderstood what i was trying to do.

I am only after the actual number.

I do not need the results, just how many results the are in total
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 10688589
You asked for an idea and I gave you one.

The below will get you the 3rd table within the search-page (which contains the number of results) and return the text to the function. You can parse it (mid/instr/left/right/whatever) for more accurate numbers. To implement other search engines, you'll need to search MSDN for help about the HTMLDocument architecture to better understand how to deal with elements and their collections/properties/methods. After that, it should be simple to view the sources of the search-engines to find out where's what.


Form1:
------------

Option Explicit

Private Const sURLGoogle As String = "http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=REPLACEME&btnG=Google+Search"
Private Sub Form_Load()
    Dim sReturn As String
    sReturn = SearchGoogle("myquery")
    MsgBox sReturn
End Sub
Private Function SearchGoogle(ByVal sQuery As String) As String
    Dim hDoc1 As New HTMLDocument, hDoc2 As New HTMLDocument, hTable As New HTMLTable
    Set hDoc1 = hDoc2.createDocumentFromUrl(Replace(sURLGoogle, "REPLACEME", sQuery), "null")
    Do Until hDoc1.readyState = "complete"
        DoEvents
    Loop
    Set hTable = hDoc1.All.tags("table")(3)
    SearchGoogle = hTable.outerText
End Function
0
 
LVL 13

Accepted Solution

by:
imarshad earned 250 total points
ID: 10689966
What about using free Google API
http://www.google.com.pk/apis/
It contains examples of using it in VB.NET but it can be tailored to use in VB
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now