0

I am trying web scraping with the bs4 and chromedriver modules. Using Visual Studio Code and Python 3.7.4. on Windows 10.

from selenium import webdriver
from bs4 import BeautifulSoup
import chromedriver

driver = webdriver.Chrome('path')
driver.get('https://webscraper.io/test-sites/e-commerce/allinone') ### (or any other website)

soup = bs.BeautifulSoup(driver.page_source, 'html.parser')

It throws me a RuntimeError "This package supports only Linux, MacOSX or Windows platforms":

 File "c:/..../scraper.py", line 17, in <module>
   import chromedriver
 File "C:\......\Python\Python37\lib\site-packages\chromedriver\__init__.py", line 16, in <module>
   raise RuntimeError('This package supports only Linux, MacOSX or Windows platforms')
RuntimeError: This package supports only Linux, MacOSX or Windows platforms

What could be the source of this error? I have seen similar reports here (https://replit.canny.io/bug-reports/p/python-3-selenium) plus some answers about the development of the chromedriver module being in progress.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
jeppoo1
  • 650
  • 1
  • 10
  • 23

3 Answers3

2

You don't need the import chromedriver, delete it. You just need to set the path to chromedriver.exe when initializing the driver

driver = webdriver.Chrome(executable_path=chromedriver_path_to_chromedriver.exe)
Guy
  • 46,488
  • 10
  • 44
  • 88
2
from selenium.webdriver import Chrome
from bs4 import BeautifulSoup
driver = Chrome()
driver.get('https://webscraper.io/test-sites/e-commerce/allinone')
soup = BeautifulSoup(driver.page_source, 'html.parser')

you don't need to import chromedriver as it is included in selenium.

Say
  • 74
  • 6
  • 2
    An accompanying explanation would help everyone understand the solution. – belwood Jan 09 '20 at 12:54
  • Thank you! This throws me the following error: _selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home_. I have included the chromedriver in my path environment variable. What could I be doing wrong? – jeppoo1 Jan 09 '20 at 14:09
  • 1
    I would like to ask you if you have downloaded the exe from here? https://sites.google.com/a/chromium.org/chromedriver/ then, add PATH – Say Jan 09 '20 at 14:24
  • @Say Thank you! Your answer solved my problem. For some reason, I had the chromedriver folders in my python site-packages folder, but they did not include the .exe file... I downloaded the .exe file and put it in a folder there, now it is working. However, your script only works for me if I put the chromedriver path inside the parentheses --> Chrome(). Without the path it throws the similar chromedriver PATH error. **By the way, do you know how I prevent Chrome from opening when I run your script? I would only like to print out the text I have scraped from the website?** – jeppoo1 Jan 10 '20 at 08:35
  • @Say I'm marking your answer as the answer even though I think the other answers will work for me too, now that I have downloaded the .exe file. – jeppoo1 Jan 10 '20 at 08:36
1

This error message...

   import chromedriver
 File "C:\......\Python\Python37\lib\site-packages\chromedriver\__init__.py", line 16, in <module>
   raise RuntimeError('This package supports only Linux, MacOSX or Windows platforms')
RuntimeError: This package supports only Linux, MacOSX or Windows platforms

...implies that the the package chromedriver which you are trying to import supports only Linux, MacOSX or Windows platforms and in short it means it is not needed.


Solution

You can safely remove import chromedriver to get rid of this error.


Details

To work with ChromeDriver and Chrome you need to download the matching version of ChromeDriver binary from ChromeDriver Google Storage. You can find a couple of detailed discussion in:

Next, you place the ChromeDriver binary anywhere within your system and provide the absolute path of the ChromeDriver through the Key / Value executable_path as follows:

from selenium import webdriver

driver = webdriver.Chrome(executable_path='/path/to/chromedriver')
driver.get('https://webscraper.io/test-sites/e-commerce/allinone') ### (or any other website)

Update

As you are on your line of code will be:

driver = webdriver.Chrome(executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get('https://webscraper.io/test-sites/e-commerce/allinone') ### (or any other website)

Incase you don't use the Key / Value pair executable_path, your Python program will look for the chromedriver in your system PATH and incase unable to find proper matching variant of chromedriver executable you will see the error:

WebDriverException: Message: 'Webdrivers' executable may have wrong permissions.

You can find a relevant detailed discussion in 'Webdrivers' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you! This works if I put the perfect path to the executable_path, meaning it ends with ...\\chromedriver\\chromedriver.exe. If it ends with \\chromedriver it throws the error "selenium.common.exceptions.WebDriverException: Message: '' executable may have wrong permissions." **By the way, do you know how I prevent the Chrome Browser from launching when I run this code? I would simply like to have Visual Studio Code terminal to print out the text I have scraped from the website, not open the browser every time I run the code.** – jeppoo1 Jan 10 '20 at 08:41
  • @jeppoo1 Glad to be able to help you. Please accept the answer by clicking on the hollow check mark beside the answer which is just below the votedown arrow so the check mark turns green. – undetected Selenium Jan 10 '20 at 08:42
  • I accepted Say:s answer because he figured out I didn't have chromedriver.exe installed in the first place. Your script does work too but only after I had installed the chromedriver.exe correctly. – jeppoo1 Jan 10 '20 at 08:44
  • Do you have insight on the question in my comment (it is in **bold**)? – jeppoo1 Jan 10 '20 at 08:45
  • @jeppoo1 Checkout the updated answer and let me know if any other questions. – undetected Selenium Jan 10 '20 at 09:55