?
Solved

Retrieve Search Engine Results

Posted on 2004-03-26
4
Medium Priority
?
291 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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…
Suggested Courses
Course of the Month12 days, 9 hours left to enroll

777 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