Recently I've been trying to do some webscraping, however I am utterly unable to run Selenium's webdriver.
I am trying to run this basic boilerplate code:
import pandas as pd
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
import time
web = webdriver.Chrome(service_args=["--verbose", "--log-path=D:\\qc1.log"])
url = 'https://www.google.com/'
web.get(url)
However this results in the following error:
raise WebDriverException(f"Service {self.path} unexpectedly exited. Status code was: {return_code}")
selenium.common.exceptions.WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 1
From doing some research, this error was because ChromeDriver was not being found
I can confirm that Chrome and Chromedriver are up to date: Chrome Version ChromeDriver Version
I can also confirm that I have ChromeDriver successfully added as a PATH environment variable
I have tried other solutions, such as using a path instead:
import pandas as pd
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
import time
PATH = 'C:\webdrivers\chromedriver.exe'
web = webdriver.Chrome(executable_path=PATH, service_args=["--verbose", "--log-path=D:\\qc1.log"])
url = 'https://www.google.com/'
web.get(url)
however the same error persists.
I have also tried adding options to the WebDriver, but to no avail.
When running without service_args added, the webpage will briefly open, before closing itself with no crash information
CodePudding user response:
You can try the other option of importing the Chromedriver through webdriver_manager like this:
from webdriver_manager.chrome import ChromeDriverManager
service = ChromeService(executable_path=ChromeDriverManager().install())
driver = webdriver.Chrome(service=service)
CodePudding user response:
Have you install the libraries, you are using in your project.
pip install -u Selenium
pip install pandas
pip install bs4
The rest would be automatically installed into your project. If you are using pycharm