2

I know there are already a couple threads about this, but I've went over them all, and this is my 3rd day trying to break through and haven't made any improvements. Here is the situation:

I'm trying to use this https://github.com/tejavoo/GooglePlayReviewScraper/blob/master/scraper.py to create a google play review scraper for my research, but continue recieving the following error:

Conda3/Python38/Windows10/Spyder 4.0.1

I've made sure that the chromedriver is in the PATH, and I've made sure it as all permissions, along with spyder and python. I also made sure it was the correct version that matches my google chrome.

I've downloaded the chromedriver, unzipped it into the folder I'm working in.

I also didn't have the Permission error (Winerror 5) Until I recently updated to spyder 4.

Please, what am I missing?

chromedriver = "C:\\Users\\james\\Downloads\\ML\\New folder\\chromedriver.exe"
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('window-size=1200x600') # optional
driver = webdriver.Chrome(executable_path = chromedriver, chrome_options = options)

The Error

Traceback (most recent call last):

  File "C:\Users\james\.conda\envs\spyder-4.0.0_1\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)

  File "C:\Users\james\.conda\envs\spyder-4.0.0_1\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 104, in __init__
    super(SubprocessPopen, self).__init__(*args, **kwargs)

  File "C:\Users\james\.conda\envs\spyder-4.0.0_1\lib\subprocess.py", line 800, in __init__
    restore_signals, start_new_session)

  File "C:\Users\james\.conda\envs\spyder-4.0.0_1\lib\subprocess.py", line 1207, in _execute_child
    startupinfo)

*PermissionError: [WinError 5] Access is denied*


During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "C:\Users\james\Downloads\ML\New folder\PlayReviews.py", line 37, in <module>
    driver = webdriver.Chrome(executable_path = chromedriver, chrome_options = options)

  File "C:\Users\james\.conda\envs\spyder-4.0.0_1\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()

  File "C:\Users\james\.conda\envs\spyder-4.0.0_1\lib\site-packages\selenium\webdriver\common\service.py", line 88, in start
    os.path.basename(self.path), self.start_error_message)

WebDriverException: 'chromedriver.exe' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

And if I change the code and place '' around chromedriver like this

chromedriver = ("C:\\Users\\james\\Downloads\\ML\\New folder\\chromedriver.exe")
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('window-size=1200x600') # optional
driver = webdriver.Chrome(executable_path= 'chromedriver', chrome_options = 'options')

I get this

runcell(0, 'C:/Users/james/Downloads/ML/New folder/PlayReviews.py')
C:\Users\james\Downloads\ML\New folder\PlayReviews.py:37: DeprecationWarning: use options instead of chrome_options
  driver = webdriver.Chrome(executable_path= 'chromedriver', chrome_options = 'options')
Traceback (most recent call last):

  File "C:\Users\james\Downloads\ML\New folder\PlayReviews.py", line 37, in <module>
    driver = webdriver.Chrome(executable_path= 'chromedriver', chrome_options = 'options')

  File "C:\Users\james\.conda\envs\spyder-4.0.0_1\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 64, in __init__
    desired_capabilities = options.to_capabilities()

AttributeError: 'str' object has no attribute 'to_capabilities'

And a webdriver.py page opens

Any help is much appreciated!

Cheers :)

Update

I tried the raw string idea as mentioned

chromedriver = "C:/Users/james/Downloads/ML/New folder/PlayReviews.py"
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('window-size=1200x600') # optional
driver = webdriver.Chrome(executable_path = r'C:\\Users\\james\\Downloads\\ML\\New folder\\chromedriver.exe', chrome_options='options')

And it seems to maybe pass it? As now I am on to this error :

runcell(0, 'C:/Users/james/Downloads/ML/New folder/PlayReviews.py')
C:\Users\james\Downloads\ML\New folder\PlayReviews.py:39: DeprecationWarning: use options instead of chrome_options
  driver = webdriver.Chrome(executable_path = r'C:\\Users\\james\\Downloads\\ML\\New folder\\chromedriver.exe', chrome_options='options')
Traceback (most recent call last):

  File "C:\Users\james\Downloads\ML\New folder\PlayReviews.py", line 39, in <module>
    driver = webdriver.Chrome(executable_path = r'C:\\Users\\james\\Downloads\\ML\\New folder\\chromedriver.exe', chrome_options='options')

  File "C:\Users\james\.conda\envs\spyder-4.0.0_1\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 64, in __init__
    desired_capabilities = options.to_capabilities()

AttributeError: 'str' object has no attribute 'to_capabilities'

However, this error, actually comes from line 64 of the webdriver.py which opens as a result of running the former

 if chrome_options:
            warnings.warn('use options instead of chrome_options',
                          DeprecationWarning, stacklevel=2)
            options = chrome_options

        if options is None:
            # desired_capabilities stays as passed in
            if desired_capabilities is None:
                desired_capabilities = self.create_options().to_capabilities()
        else:
            if desired_capabilities is None:
                desired_capabilities = options.to_capabilities()
            else:
                desired_capabilities.update(options.to_capabilities())
JamesArthur
  • 496
  • 7
  • 18

4 Answers4

2

I have seen similar permission errors when the executable path was not a raw string. Have you tried formatting it like this?

driver = webdriver.Chrome(executable_path = r'C:\\Users\\james\\Downloads\\ML\\New folder\\chromedriver.exe', chrome_options = options)
0buz
  • 3,443
  • 2
  • 8
  • 29
  • Thanks! I had given that a shot, tried agian, but the same error, unfortunately no change. – JamesArthur Feb 18 '20 at 16:34
  • Just had a look at your update. You are still calling one of the parameters incorrectly when instantiating Chrome, namely `chrome_options='options'`. It does not need the quotes; please see my answer. – 0buz Feb 19 '20 at 16:55
2

I've finally managed to figure out where I went wrong.

While I had the PATH and all correct - the Chromdriver.exe file was not in my Python/scripts folder.

After setting it there, re-placing the PATH, all works well!! :)

JamesArthur
  • 496
  • 7
  • 18
1

Here is part of a little script I made to login and check for new questions on here. It is in a different library in C# but maybe it is still relevant and will help you discover the issue. Anyways the code is below hope it helps.

The only thing you aren't doing that I am is setting the BinaryLocation on the ChromeOptions and I am discovering the driver directory at run-time.

Also, sometimes the error messages like those are caused by exactly what they say is wrong. Maybe in order to run the selenium driver it may require more elevated windows permissions like when you right click and say run as administrator on programs sometimes. Have you tried running the terminal/command line that you are trying to run the python script on as an admin?

ChromeOptions options = new ChromeOptions();
options.BinaryLocation = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";

using (IWebDriver driver = new ChromeDriver(GetChromeDriverDirectory(), options))
{
    driver.NavigateToUrl("https://stackoverflow.com/questions/tagged?sort=Newest&filters=NoAnswers&tagMode=Watched");
}

// Here is the method I use to get the Chrome driver directory.
private static string GetChromeDriverDirectory() => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  • Thanks! Yes I have read a bit about the binarylocation options, but not too familiar with it. I'll have to look a bit deeper though, still trying to figure out how to use it in my case – JamesArthur Feb 18 '20 at 16:35
0

You need to take care of a few things:

  • While using Selenium's client, to pass the absolute path of the ChromeDriver you need to use the single forward slash along with the raw i.e. r switch.

  • The argument chrome_options is now deprecated, instead you need to use options.

  • Your effective code block will be:

      options = webdriver.ChromeOptions()
      options.headless = True
      # previously: options.set_headless(headless=True)
      # long ago: options.add_argument('--headless')
      options.add_argument('--window-size=1200x600')
      driver = webdriver.Chrome(executable_path = r'C:\Users\james\Downloads\ML\New folder\chromedriver.exe', options = options)
    

References

You can find a couple of relevant discussions in:

drigoangelo
  • 127
  • 1
  • 1
  • 11
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352