|
1 | 1 | from googlesearch import search
|
2 | 2 | import sys
|
3 | 3 |
|
| 4 | + |
4 | 5 | class googlesearch:
|
5 | 6 |
|
6 | 7 | def __init__(self):
|
@@ -23,7 +24,8 @@ def set_search_text(self):
|
23 | 24 | def perform_search(self):
|
24 | 25 | try:
|
25 | 26 | # 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) |
27 | 29 | self.search_results = results
|
28 | 30 | except Exception as e:
|
29 | 31 | print(e)
|
@@ -32,7 +34,8 @@ def perform_search(self):
|
32 | 34 | print("Google search performed successfully")
|
33 | 35 |
|
34 | 36 | 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)) |
36 | 39 |
|
37 | 40 | count = 1
|
38 | 41 | for search_res in self.search_results:
|
@@ -44,18 +47,18 @@ def print_search_res(self):
|
44 | 47 | def main():
|
45 | 48 | google_search_bot = googlesearch()
|
46 | 49 |
|
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 | + |
55 | 58 | choice = int(input(''))
|
56 | 59 |
|
57 |
| -if choice == 1: |
58 |
| -google_search_bot.set_search_count() |
| 60 | +if choice == 1: |
| 61 | +google_search_bot.set_search_count() |
59 | 62 | elif choice == 2:
|
60 | 63 | google_search_bot.set_search_text()
|
61 | 64 | elif choice == 3:
|
@@ -65,11 +68,12 @@ def main():
|
65 | 68 | else choice == 5:
|
66 | 69 | sys.exit()
|
67 | 70 |
|
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 | + |
73 | 77 |
|
74 | 78 | if __name__ == '__main__':
|
75 | 79 | main()
|
0 commit comments