|
@@ -7,6 +7,8 @@
|
|
|
|
|
|
#########################################################################################
|
|
#########################################################################################
|
|
|
|
|
|
|
|
+#Import required libraries
|
|
|
|
+
|
|
from time import time
|
|
from time import time
|
|
from googlesearch import search
|
|
from googlesearch import search
|
|
import sys
|
|
import sys
|
|
@@ -15,11 +17,13 @@ import webbrowser
|
|
search_query = input('What do you want to search for on the web?: ')
|
|
search_query = input('What do you want to search for on the web?: ')
|
|
result_num = input('How many results do you want to retrieve from the web?: ')
|
|
result_num = input('How many results do you want to retrieve from the web?: ')
|
|
|
|
|
|
|
|
+#Verify user input
|
|
try:
|
|
try:
|
|
int_result_num = int(result_num)
|
|
int_result_num = int(result_num)
|
|
except:
|
|
except:
|
|
sys.exit('The number of results you wanted to retrieve was not a number. Exiting program...')
|
|
sys.exit('The number of results you wanted to retrieve was not a number. Exiting program...')
|
|
|
|
|
|
|
|
+#Display web results
|
|
print('The top %d results from the web are:' %(int_result_num))
|
|
print('The top %d results from the web are:' %(int_result_num))
|
|
|
|
|
|
start = time()
|
|
start = time()
|
|
@@ -28,6 +32,8 @@ for url in search(search_query, tld='com', stop=int_result_num):
|
|
end = time()
|
|
end = time()
|
|
|
|
|
|
print('Found %d results from the web in %s' %(int_result_num, end - start) + ' seconds.')
|
|
print('Found %d results from the web in %s' %(int_result_num, end - start) + ' seconds.')
|
|
|
|
+
|
|
|
|
+#Ask user if they want to open the links in the web browser with validation
|
|
open_in_browser = input('Do you want to open the given URLs in your web browser (Y/N)? ')
|
|
open_in_browser = input('Do you want to open the given URLs in your web browser (Y/N)? ')
|
|
|
|
|
|
if open_in_browser.upper() == 'Y':
|
|
if open_in_browser.upper() == 'Y':
|