I'm new to using Selenium. However, I am getting an error like this at the beginning. I tried the solutions found on the site but I still get the same error.
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
webdriver.Chrome(ChromeDriverManager().install())
driver_path = (r"C:\Users\win10\Desktop\Test\chromedriver_win32.exe")
browser = webdriver.Chrome(executable_path=driver_path)
Error Message:
selenium.common.exceptions.WebDriverException: Message: 'chromedriver_win32.exe' executable
needs to be in PATH.
CodePudding user response:
Basically the chromedriver_win32.exe is not found in your path. You can add the chrome driver to a directory which is already exist in the path. you can replace driver path by the below line to find absolute path.
driver_path = os.path.abspath("chromedriver_win32.exe")
Please make sure you have the chrome driver in your system if the above step doesn't work then most likely the name of the executable must be different.
CodePudding user response:
Try this.
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
url = 'https://docs.python.org/3/tutorial/index.html'
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument("user-agent=arush")
driver = webdriver.Chrome(executable_path = r'C:\Users\Arush\Python\chromedriver.exe', options = chrome_options)
driver.get(url)
html = driver.page_source
driver.close()
soup = BeautifulSoup(html, features = 'lxml')
print(soup)
Change the values of url and executable_path accordingly. I'll attach the chromedriver v2.34 which is compatible with Google Chrome v63. https://drive.google.com/file/d/1cyXu4VsuGuhUXoHJssjzxCI4Nt9tHEah/view?usp=sharing