Google Answers Logo
View Question
 
Q: Macro or Simple Script that will look up URLs in Google or in a DB ( No Answer,   6 Comments )
Question  
Subject: Macro or Simple Script that will look up URLs in Google or in a DB
Category: Computers > Programming
Asked by: parallel54-ga
List Price: $50.00
Posted: 12 May 2005 12:06 PDT
Expires: 11 Jun 2005 12:06 PDT
Question ID: 520971
I get lots of media lists that list media titles; "New York Times" but
not the associated URLs (http://wwwnytimes.com). I then have to spend
ages looking up the New York Times in either our own DB (MS Access) or
via Google to match the Media Title with an actual URL.
It sounds easy but imagine you have 1,000 Media Titles in a
spreadsheet and you need to match URLs against each. Time Consuming!
Usually the lists are in EXCEL format. So I would like a suggestion for:
a) A Macro/Script that will let me run the media title query into
Google and so attempt to match up the Media Title with a URL. Of
course it won't always work but it will save time when it does.
b) A Query/Macro that will let me do the same with my own Access DB.
Can send examples if it helps.
Will pay $25.00 for a solution to a) OR b) so $50 for the full set.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Macro or Simple Script that will look up URLs in Google or in a DB
From: rion-ga on 25 May 2005 21:49 PDT
 
so you want a program that reads a string from a list, types that into
google, and then gives you the first website that google comes up
with?
Subject: Re: Macro or Simple Script that will look up URLs in Google or in a DB
From: parallel54-ga on 26 May 2005 02:45 PDT
 
Yes exactly that. It wouyld extract a record from say a field in EXCEL
query Google then return the result to a field next to the original
field in EXCEL. So next to "Wall Street Journal" it would hopefully
return "http://www.wsj.com"
Subject: Re: Macro or Simple Script that will look up URLs in Google or in a DB
From: coolchap_here-ga on 20 Jul 2005 00:42 PDT
 
Hi,
I am having solution for problem (a).
Please respond back to this comment if you are still looking for the solution.

Regards.
Subject: Re: Macro or Simple Script that will look up URLs in Google or in a DB
From: parallel54-ga on 24 Jul 2005 13:39 PDT
 
Hi there,

Sorry for the delay in responding but yes I am still looking for a solution.

So just to clarify the script would:

a) Take a "Media Title" from EXCEL; for example "Wall Street Journal"
b) Query Google for this Media title;
c) Return Google's top result; hopefully "http://www.wsj.com".
d) Put this result in the adjacent column (same row) as the "Media Title".
e) Repeat this for as many fields as required. Could be several hundred.

Many thanks

TIM
Subject: Re: Macro or Simple Script that will look up URLs in Google or in a DB
From: coolchap_here-ga on 25 Jul 2005 10:43 PDT
 
Hi there,

Here is the VBScript you are looking for:
Save the script as test.vbs and do the following
1) Once you double click the vbs file, a file open dialog will come up
and it will ask you to select the excel sheet that contains the search
keywords. Select the file.
2) Then in the next two input boxes provide the starting row and
column no. where the words are stored in the excel sheet
3) THe script will check whether selected file is already opened or not.
4) The results will be stored in the next column.

Please revert back in case of any issues.


the script goes here.....

===============================================
TEST.VBS
===============================================

Call FindLinks()
msgbox "SUCCESS"
Sub FindLinks()
    On Error Resume Next
    Dim objExcel
    Dim book 
    Dim strLink
    Dim strFilter
    Const CLOSED_OR_CANCELLED = 0
    Dim intGetRow
    Dim intGetColumn
    Dim intCounter
    Dim strFile
    
    intColumn=1
    
    set objExcel = wscript.CreateObject("Excel.Application")
    
    'loop until user selects a .xls file.
	Do
		'File filters
 		strFilter = "All Microsoft Excel Files (*.xl; *.xls; *.xlt; *.htm;
*.html),*.xl; *.xls; *.xlt; *.htm; *.html"
		'get the Excel file name 
		strFile = objExcel.GetOpenFilename(strFilter,1)
		If strFile = CLOSED_OR_CANCELLED Then 
			msgbox "CANCELLED"
			Call WScript.Quit(1)
		End If
		If err.Number <> 0 Then 
		    msgbox err.number & err.Description 
		    WScript.Quit(1)
		End If
    Loop While strFile = ""
   
    Do 
	    If IsFileOpen(strFile) Then
	    	msgbox "The excel sheet you selected is already opened. Please
close it to proceed."
	    End If
	Loop While IsFileOpen(strFile)
	
    objExcel.Workbooks.Open(strFile)
    objExcel.Visible = True
    
    intGetRow = CInt(InputBox("Please enter the row number from where
the search words are starting in the selected excel sheet", "tiwari
dot vikas at gmail dot com",1))
    intGetColumn = CInt(InputBox("Please enter the column number where
the search words are stored in the selected excel sheet", "tiwari dot
vikas at gmail dot com",1))
  
    
    For intCounter = intGetRow to 1000
        If objExcel.Cells(intCounter,intGetColumn) <> "" Then
            strLink = GetGoogleLink(objExcel.Cells(intCounter,intGetColumn))
            objExcel.Cells(intCounter,intGetColumn+1) = strLink
            'Exit For
        Else
            Exit For
        End If
    Next
    'save the sheet
    objExcel.ActiveWorkbook.Save
    objExcel.ActiveWorkbook.Close
    set objExcel = Nothing
    On Error Goto 0
End Sub

Function GetGoogleLink(strSearchKeyword)
    On Error Resume Next
    Dim objExplorer
    Dim arrKeywords
    Dim strURL
    strURL = "://www.google.co.in/search?hl=en&q="
    arrKeywords = Split(strSearchKeyword,chr(32))
    For i =0 To UBound(arrKeywords)
        strURL = strURL & arrKeywords(i) & "+" 
    Next
    strURL = Mid(strURL,0,Len(strURL)-1) & "&meta="
    Set objExplorer = WScript.CreateObject("InternetExplorer.Application")
    objExplorer.Navigate(strURL)  
    do
        WScript.Sleep(100)
    Loop while objExplorer.Busy = True
    strInnerText = objExplorer.Document.body.innerHTML
    strStartPosition = InStr(strInnerText, "class=g")
    strLinkStart = InStr(strStartPosition, strInnerText, "href=")
    strLink = Mid(strInnerText, strLinkStart + 6, InStr(strLinkStart +
6, strInnerText, chr(34))- strLinkStart-6)
    GetGoogleLink = strLink
    On Error Goto 0
End Function

Function IsFileOpen(ByVal sFileName)
	Dim file
	Dim iErrNum
	Dim objFSO
	Const ForAppending = 8
	
	On Error Resume Next 
	Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
	' Attempt to open the file and lock it.
	Set file = objFSO.OpenTextFile(sFileName, ForAppending, False)
	iErrNum = Err.Number ' Save the error number that occurred.
	file.Close ' Close the file.
	On Error GoTo 0 ' Turn error checking back on.
	' Check to see which error occurred.
	Select Case iErrNum
		' No error occurred.
		' File is NOT already open by another user.
		Case 0
			IsFileOpen = False
		' Error number for "Permission Denied."
		' File is already opened by another user.
		Case 70  ' Error number for "Permission Denied."
			IsFileOpen = True
			
		' Another error occurred.
		Case Else
		    Set objFSO = Nothing
			Err.Raise iErrNum
	End Select
	Set objFSO = Nothing
End Function
Subject: Re: Macro or Simple Script that will look up URLs in Google or in a DB
From: coolchap_here-ga on 03 Aug 2005 05:43 PDT
 
Hi there,

I posted above script few days back but got no response from you. 

Please let me know whether it is working fine or not. 

Thanks.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy