Solved

Retrieve Search Engine Results

Posted on 2004-03-26
4
288 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

732 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