11from googlesearch import search
22import sys
33
4+
45class googlesearch :
56
67 def __init__ (self ):
@@ -23,7 +24,8 @@ def set_search_text(self):
2324 def perform_search (self ):
2425 try :
2526 # Perform the Google search
26- results = search (self .keyword_to_search , num_results = self .search_count )
27+ results = search (self .keyword_to_search ,
28+ num_results = self .search_count )
2729 self .search_results = results
2830 except Exception as e :
2931 print (e )
@@ -32,7 +34,8 @@ def perform_search(self):
3234 print ("Google search performed successfully" )
3335
3436 def print_search_res (self ):
35- print ("The search results for {} keyword are:" .format (self .keyword_to_search ))
37+ print ("The search results for {} keyword are:" .format (
38+ self .keyword_to_search ))
3639
3740 count = 1
3841 for search_res in self .search_results :
@@ -44,18 +47,18 @@ def print_search_res(self):
4447def main ():
4548 google_search_bot = googlesearch ()
4649
47- while True :
48- print ("Select any one of the valid operations which are listed below:" )
49- print ("1. To set the number of searches we need to display for each Google Search." )
50- print ("2. To enter the keyword for the Google Search." )
51- print ("3. To perform Google Search for the keyword entered by the user." )
52- print ("4. To print the Google search results obtained after searching." )
53- print ("5. To exit from the code execution." )
54-
50+ while True :
51+ print ("Select any one of the valid operations which are listed below:" )
52+ print ("1. To set the number of searches we need to display for each Google Search." )
53+ print ("2. To enter the keyword for the Google Search." )
54+ print ("3. To perform Google Search for the keyword entered by the user." )
55+ print ("4. To print the Google search results obtained after searching." )
56+ print ("5. To exit from the code execution." )
57+
5558 choice = int (input ('' ))
5659
57- if choice == 1 :
58- google_search_bot .set_search_count ()
60+ if choice == 1 :
61+ google_search_bot .set_search_count ()
5962 elif choice == 2 :
6063 google_search_bot .set_search_text ()
6164 elif choice == 3 :
@@ -65,11 +68,12 @@ def main():
6568 else choice == 5 :
6669 sys .exit ()
6770
68- print ("To continue with the code execution, enter 'y' or 'n':" )
69- continue_or_exit = input ()
70-
71- if continue_or_exit == 'n' or continue_or_exit == 'N' :
72- sys .exit ()
71+ print ("To continue with the code execution, enter 'y' or 'n':" )
72+ continue_or_exit = input ()
73+
74+ if continue_or_exit == 'n' or continue_or_exit == 'N' :
75+ sys .exit ()
76+
7377
7478if __name__ == '__main__' :
7579 main ()
0 commit comments