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:
JavaScript
x
11
11
1
from selenium import webdriver
2
from selenium.webdriver.support.wait import WebDriverWait
3
import time
4
chromeOptions = webdriver.ChromeOptions()
5
chromeOptions.add_argument("--no-sandbox")
6
chromeOptions.add_argument("--headless")
7
driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver', chrome_options=chromeOptions)
8
driver.get("https://www.bol.com/nl/")
9
10
print(driver.page_source)
11
Here is my error:
JavaScript
1
12
12
1
Traceback (most recent call last):
2
File "product_tracker.py", line 10, in <module>
3
print(driver.page_source)
4
File "/home/tychokoster/py36/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 679, in page_source
5
return self.execute(Command.GET_PAGE_SOURCE)['value']
6
File "/home/tychokoster/py36/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
7
self.error_handler.check_response(response)
8
File "/home/tychokoster/py36/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
9
raise exception_class(message, screen, stacktrace)
10
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
11
(Session info: headless chrome=79.0.3945.130)
12
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:
JavaScript
1
2
1
driver = webdriver.Chrome("D:/Testing Purpose/Pycharm Testing/DemoProject/Driver/chromedriver.exe", chrome_options=chromeOptions)
2
I have already tested using Pycharm IDE same above code working fine.