# -*- coding: utf-8 -*- import json, requests, sys, time, urllib.request, urllib.parse def title(): print ("\n\t Test script ") print ("\t---------------\n") def usage(): title() print ("\n Usage: python test.py <domain/ip> <searchlist>\n") def timer(): now = time.localtime(time.time()) return time.asctime(now) if len(sys.argv) <= 2: usage() sys.exit(1) else: title() domain = "site:" + sys.argv[1] file_name = sys.argv[2] def showsome(domain): fopen = open(file_name, 'r') counter = 0 for x in fopen.readlines(): counter = counter + 1 google_search = domain + " " + x.strip('\n') query = urllib.parse.urlencode({'q': google_search}) url = ('http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' % query) search_response = urllib.request.urlopen(url) search_results = search_response.read().decode("utf-8") results = json.loads(search_results) data = (results['responseData']) if len(data['results']) > 0: print('Total results: %s' % data["cursor"]["estimatedResultCount"]) hits = (data['results']) print ('Top %d hits:' % len(hits)) for h in hits: print ('[+]', h['url']) #print ('For more results, see %s' % data["cursor"]["moreResultsUrl"]) fopen.close() showsome(domain)
Если его запустить, он выдает ошибку:
C:\Users\User>python C:\test.py example.com "C:\search.txt" Traceback (most recent call last): File "C:\test.py", line 52, in <module> showsome(domain) File "C:\test.py", line 44, in showsome if len(data['results']) > 0: TypeError: 'NoneType' object is not subscriptable
В гугле ответ найти не получилось.
Что я делаю не так?
