#!/usr/bin/env python # # googleSearch.py # # Copyright 2009 Serge Gorbunov # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. import urllib import simplejson import sys import time import os # Add a search keyword in the searchKeywords array # This script takes 40 results from google and saves it to searchResults.txt file # Only urls for the search are saved. searchKeywords = ['honeynet', 'python'] def main(): totalResults = 0 f = open('searchResults.txt', 'w') for query in searchKeywords: print "Searching %s" % query query = urllib.urlencode({'q' : query}) sCounter = 0 urls = [] while ( sCounter <= 36 ): url = 'http://ajax.googleapis.com/ajax/services/search/web?start=%d&v=1.0&%s' \ % (sCounter, query) search_results = urllib.urlopen(url) json = simplejson.loads(search_results.read()) results = json['responseData']['results'] for i in results: f.write('%s\n' % i['url']) totalResults += 1 sCounter += 4 # close the results file f.close() if __name__=='__main__': main()