I am trying to get the page content from a webpage, with the use of selenium and chromedriver. I am using an Ubuntu 18.04 subsystem on Windows. The driver.get method works, but getting the page content does not. Here is my code:
from selenium import webdriver from selenium.webdriver.support.wait import WebDriverWait import time chromeOptions = webdriver.ChromeOptions() chromeOptions.add_argument("--no-sandbox") chromeOptions.add_argument("--headless") driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver', chrome_options=chromeOptions) driver.get("https://www.bol.com/nl/") print(driver.page_source)
Here is my error:
Traceback (most recent call last): File "product_tracker.py", line 10, in <module> print(driver.page_source) File "/home/tychokoster/py36/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 679, in page_source return self.execute(Command.GET_PAGE_SOURCE)['value'] File "/home/tychokoster/py36/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/home/tychokoster/py36/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: chrome not reachable (Session info: headless chrome=79.0.3945.130)
Don’t really know what to do anymore, I tried changing chromedriver versions, maybe the problem is using a subsystem but I am not sure.
Advertisement
Answer
Try with : executable_path with “absolute_path..upto..driver-EXE” not only a directory.
for example:
driver = webdriver.Chrome("D:/Testing Purpose/Pycharm Testing/DemoProject/Driver/chromedriver.exe", chrome_options=chromeOptions)
I have already tested using Pycharm IDE same above code working fine.