Solved

Retrieve Search Engine Results

Posted on 2004-03-26
4
287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

740 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