#A tiny python Google results opener.
#MAR2010
import sys
import urllib
import urllib2
import re
import os
def usage():
print "[!] Usage: " + sys.argv[0] + "
if (len(sys.argv) != 3):
usage()
sys.exit(-1)
iexplore = 'ie'
firefox = 'ff'
chrome = 'ch'
command_ie = '"c:\\Program Files\\Internet Explorer\\iexplore.exe" '
command_ff = '"c:\\Program Files\\Mozilla Firefox\\firefox.exe" '
command_ch = '"c:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" '
user_browser = str(sys.argv[1])
user_query = str(sys.argv[2])
query_list = user_query.split(" ")
the_query = ""
for i in range(len(query_list)):
query_list[i] = urllib.quote(query_list[i])
the_query = the_query+query_list[i]+"+"
the_query = the_query[:-1]
final_url = "http://www.google.com.co/search?hl=es&q="+the_query+"&btnG=Buscar+con+Google&meta="
#print "[+] final_url: "+final_url
accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"
user_agent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506; InfoPath.2; OfficeLiveConnector.1.3; OfficeLivePatch.0.0; .NET CLR 3.5.21022; Google-TR-5.8.809.23506-en)"
opener = urllib2.build_opener()
opener.addheaders = [('Accept', accept)]
opener.addheaders = [('User-Agent', user_agent)]
try:
response = opener.open(final_url)
except URLError, e:
if hasattr(e, 'reason'):
print 'We failed to reach a server.'
print 'Reason: ', e.reason
elif hasattr(e, 'code'):
print 'The server couldn\'t fulfill the request.'
print 'Error code: ', e.code
else:
# everything is fine
the_page = response.read()
grab = re.findall('
for i in range(len(grab)):
link = re.findall('(?:href)="(.+?)"', grab[i])
links.append(link[0])
command = ""
if user_browser==firefox:
command = command_ff
elif user_browser==chrome:
command = command_ch
else:
command = command_ff
for i in range(len(links)):
final_command = command+links[i]
os.system(final_command)
#EOS
No comments:
Post a Comment