-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrowser_search.py
More file actions
38 lines (28 loc) · 1.08 KB
/
browser_search.py
File metadata and controls
38 lines (28 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.service import Service
import time
# Path to the EdgeDriver executable
driver_path = "F:/edgedriver_win64/msedgedriver.exe"
# Create a new instance of the Edge driver
service = Service(executable_path=driver_path)
driver = webdriver.Edge(service=service)
try:
# Get the search query from the user
search_query = input("Enter your search query: ")
# Open Google's homepage
driver.get("https://www.google.com")
# Find the search box using its name attribute value
search_box = driver.find_element(By.NAME, "q")
# Type in the search query
search_box.send_keys(search_query)
# Submit the search query
search_box.send_keys(Keys.RETURN)
# Wait for the results page to load and display the results
time.sleep(5) # Increase wait time if necessary
# Print the title of the search results page
print(driver.title)
finally:
# Close the browser window, even on exceptions
driver.quit()