Skip to content

Commit f5eb4f6

Browse files
committed
Adding google search automation using python script
1 parent f8a43c6 commit f5eb4f6

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
```markdown
3+
# Google Search Bot
4+
5+
This is a Python script that allows you to perform Google searches and display the search results. It uses the `googlesearch` library to interact with the Google search engine.
6+
7+
## Usage
8+
9+
1. Set the number of search results to display.
10+
2. Enter the keyword to search on Google.
11+
3. Perform the Google search.
12+
4. Print the search results obtained.
13+
14+
## Getting Started
15+
16+
To get started with the Google Search Bot, follow these steps:
17+
18+
1. Clone the repository:
19+
20+
```bash
21+
git clone https://github.com/your-username/google-search-bot.git
22+
```
23+
24+
2. Install the required dependencies:
25+
26+
```bash
27+
pip install googlesearch
28+
```
29+
30+
3. Run the script:
31+
32+
```bash
33+
python google_search_bot.py
34+
```
35+
36+
## Contributing
37+
38+
Contributions are welcome! If you have any ideas, suggestions, or bug reports, please create an issue or submit a pull request.
39+
40+
## License
41+
42+
This project is licensed under the [MIT License](LICENSE).
43+
```
44+
45+
You can save this content in a file named `README.md` in your GitHub repository. Remember to replace `your-username` in the repository URL with your actual GitHub username.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
from googlesearch import search
2+
import sys
3+
4+
class googlesearch:
5+
6+
def __init__(self):
7+
self.search_count = None
8+
self.keyword_to_search = None
9+
self.search_results = None
10+
11+
def set_search_count(self):
12+
# Set the number of search results to display
13+
print("Enter the count of search results you want to display:")
14+
count = int(input())
15+
self.search_count = count
16+
17+
def set_search_text(self):
18+
# Set the keyword to search on Google
19+
print("Enter the text you want to search on Google:")
20+
text = input()
21+
self.keyword_to_search = text
22+
23+
def perform_search(self):
24+
try:
25+
# Perform the Google search
26+
results = search(self.keyword_to_search, num_results=self.search_count)
27+
self.search_results = results
28+
except Exception as e:
29+
print(e)
30+
print("Google search faced an exception")
31+
32+
print("Google search performed successfully")
33+
34+
def print_search_res(self):
35+
print("The search results for {} keyword are:".format(self.keyword_to_search))
36+
37+
count = 1
38+
for search_res in self.search_results:
39+
# Print the search results
40+
print("Search No {}: {}".format(count, search_res))
41+
count += 1
42+
43+
44+
def main():
45+
google_search_bot = googlesearch()
46+
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+
55+
choice = int(input())
56+
57+
if choice == 1:
58+
google_search_bot.set_search_count()
59+
elif choice == 2:
60+
google_search_bot.set_search_text()
61+
elif choice == 3:
62+
google_search_bot.perform_search()
63+
elif choice == 4:
64+
google_search_bot.print_search_res()
65+
elif choice == 5:
66+
sys.exit()
67+
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()
73+
74+
if __name__ == '__main__':
75+
main()

0 commit comments

Comments
 (0)