Advertisement
kingbode

Untitled

Sep 21st, 2023
1,775
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. from selenium import webdriver
  2. from selenium.webdriver.chrome.service import Service
  3. import time
  4.  
  5. def initializeDriver():
  6.  
  7.     ### Initialise Driver for all search engines here !!
  8.     options = webdriver.ChromeOptions()
  9.  
  10.     options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors"])
  11.     options.add_experimental_option("useAutomationExtension", True)
  12.     options.add_argument('--disable-gpu')
  13.     # to hide the browser
  14.     # options.add_argument('--headless')
  15.  
  16.     service = Service('chromedriver.exe')
  17.  
  18.     return webdriver.Chrome(service=service, options=options)
  19.  
  20.  
  21.  
  22. driver = initializeDriver()
  23.  
  24. driver.get("https://www.google.com")
  25.  
  26.  
  27. time.sleep(1)
  28. # change language to English
  29. driver.find_element("css selector", value = "#SIvCob > a").click()
  30. # find element by CSS selector
  31. searchTextBox = driver.find_element( "css selector", value = "#APjFqb")
  32.  
  33. searchTextBox.send_keys("Prayer Times in Gaza")
  34. # press enter
  35. searchTextBox.submit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement