Created
September 8, 2015 10:35
-
-
Save openrijal/83934ad015b16bc3b2dd to your computer and use it in GitHub Desktop.
Python Script to estimate number of results in a google search. Also supports site: and inurl: queries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
from optparse import OptionParser | |
import json | |
import urllib | |
def calculate(searchfor): | |
query = urllib.urlencode({'q': searchfor}) | |
url = 'http://ajax.googleapis.com/ajax/services/search/web?v=2.0&%s' % query | |
search_response = urllib.urlopen(url) | |
search_results = search_response.read() | |
results = json.loads(search_results) | |
data = results['responseData'] | |
print 'Total Estimated Results: %s' % data['cursor']['estimatedResultCount'] | |
def main(): | |
parser = OptionParser("""%prog --q <keyword> --site <http://example.com> --inurl <blog>""") | |
pao = parser.add_option | |
pao("--q", action="store") | |
pao("--site", action="store") | |
pao("--inurl", action="store") | |
(options, args) = parser.parse_args() | |
if not options.q: | |
if not options.site: | |
sys.exit(parser.get_usage()) | |
if options.q: | |
params = options.q | |
if options.site: | |
params = 'site:' + options.site | |
if options.inurl: | |
params += ' inurl:' + options.inurl | |
calculate(params) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment