Summary of what I am trying to achieve: Use the selenium package in python within a JupyterLabs (cloud) environment.
Suspected Issue: I suspect the issue/ (or complication) is resulting from the JupyterLabs environment.
Why do I have to use JupyterLabs? My machine only allow me to run python via JupyterLabs
Below explains the code I tried. I feel like I am close but just overlooking something. Really appreciate any guidance. Thanks in advance!
I am using a machine which runs Python on JupyterLabs
pip install selenium
pip install webdriver_manager
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.service import Options
from webdriver_manager.chrome import ChromeDriverManager
service = Service(executable_path=ChromeDriverManager().install())
driver = webdriver.Chrome(service=service)
driver.get(";)
I receive the error: "cannot find Chrome binary"
I believe because this is JupyterLabs, it cannot read Chrome from my local Windows computer. So I downloaded the latest Win64 Chrome and drag and drop "chrome.exe" into my JupyterLabs file panel.
First, to ensure I am referencing the Chrome correctly, I checked the path.
import os
os.getcwd()
It returned: '/x1/jon'
Next, I added these 2 lines of code to the codes above:
options=Options()
options.add_argument('--headless')
options.binary_location = '/x1/jon/chrome.exe'
And, I updated:
driver = webdriver.Chrome(service=service, options=options)
The final code is:
options=Options()
options.add_argument('--headless')
options.binary_location = '/x1/jon/chrome.exe'
service = Service(executable_path=ChromeDriverManager().install())
driver = webdriver.Chrome(service=service, options=options)
driver.get(";)
Now, I get the error: "Chrome failed to start: exited abnormally"
Would really appreciate any help or pointers on this. Many many thanks!
The first step was to get ChromeDriver running, so I used
service = Service(executable_path=ChromeDriverManager().install())
Next, since it is JupyterLabs, I think it cannot read my Chrome. So I downloaded a Win64 Chrome.
I dragged and drop the chrome.exe into JupyterLabs and reference it.
However, I am still running into an error.
Summary of what I am trying to achieve: Use the selenium package in python within a JupyterLabs (cloud) environment.
Suspected Issue: I suspect the issue/ (or complication) is resulting from the JupyterLabs environment.
Why do I have to use JupyterLabs? My machine only allow me to run python via JupyterLabs
Below explains the code I tried. I feel like I am close but just overlooking something. Really appreciate any guidance. Thanks in advance!
I am using a machine which runs Python on JupyterLabs
pip install selenium
pip install webdriver_manager
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.service import Options
from webdriver_manager.chrome import ChromeDriverManager
service = Service(executable_path=ChromeDriverManager().install())
driver = webdriver.Chrome(service=service)
driver.get("https://quotes.toscrape")
I receive the error: "cannot find Chrome binary"
I believe because this is JupyterLabs, it cannot read Chrome from my local Windows computer. So I downloaded the latest Win64 Chrome and drag and drop "chrome.exe" into my JupyterLabs file panel.
First, to ensure I am referencing the Chrome correctly, I checked the path.
import os
os.getcwd()
It returned: '/x1/jon'
Next, I added these 2 lines of code to the codes above:
options=Options()
options.add_argument('--headless')
options.binary_location = '/x1/jon/chrome.exe'
And, I updated:
driver = webdriver.Chrome(service=service, options=options)
The final code is:
options=Options()
options.add_argument('--headless')
options.binary_location = '/x1/jon/chrome.exe'
service = Service(executable_path=ChromeDriverManager().install())
driver = webdriver.Chrome(service=service, options=options)
driver.get("https://quotes.toscrape")
Now, I get the error: "Chrome failed to start: exited abnormally"
Would really appreciate any help or pointers on this. Many many thanks!
The first step was to get ChromeDriver running, so I used
service = Service(executable_path=ChromeDriverManager().install())
Next, since it is JupyterLabs, I think it cannot read my Chrome. So I downloaded a Win64 Chrome.
I dragged and drop the chrome.exe into JupyterLabs and reference it.
However, I am still running into an error.
Share asked Feb 11 at 1:55 learningstufflearningstuff 1 4- Could you please try correcting this line "from selenium.webdriver.chrome.service import Options" ? Correct line will be "from selenium.webdriver.chrome.options import Options". Thank you. – Subir Chowdhury Commented Feb 11 at 3:08
- @SubirChowdhury -- Really appreciate your input. I corrected the line to the one you specified but it is still showing the same error: "Chrome failed to start: exited abnormally (The process started from chrome location /x1/jon/chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)" – learningstuff Commented Feb 11 at 15:30
- I tested the initial part of the code from your question using JupyterLab. After correcting this line, the first part of the code functions properly in my testing. – Subir Chowdhury Commented Feb 11 at 15:57
- mind sending me the code you tried? also, which 'chrome binary' did you download from googlechromelabs.github.io/chrome-for-testing and dragged it into the jupyterlabs file panel? – learningstuff Commented Feb 11 at 17:02
1 Answer
Reset to default 0In my testing both scripts are functional. First script (using the default chrome installation):
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
chrome_options = Options()
chrome_options.add_argument("--headless")
service = Service(executable_path=ChromeDriverManager().install())
driver = webdriver.Chrome(service=service, options=chrome_options)
driver.get("https://quotes.toscrape")
print(driver.title)
driver.quit()
Second script:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
options = Options()
options.add_argument('--headless')
options.binary_location = 'chrome/chrome.exe' # Ensure this path is correct
service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=service, options=options)
driver.get("https://quotes.toscrape")
print(driver.title)
driver.quit()
For the second script, I downloaded the ChromeDriver from this link https://storage.googleapis/chrome-for-testing-public/133.0.6943.53/win64/chrome-win64.zip. My Chrome executable file is located at "chrome/chrome.exe".
When I attempted to add a slash before the file location, such as "/chrome/chrome.exe", I encountered the error:
"error: no chrome binary at /chrome/chrome.exe"
Therefore, I believe you should remove the leading slash from your executable file location ("/x1/jon/chrome.exe"). Additionally, I did not import the os module.
Or please make an effort using other drivers. I also attempted using geckodriver (firfox). To utlize geckodriver please download win64 version from here https://github/mozilla/geckodriver/releases. Below is the script:
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
options = Options()
options.add_argument('--headless')
custom_driver_path = r'D:\python\geckodriver.exe'
service = Service(executable_path=custom_driver_path)
driver = webdriver.Firefox(service=service, options=options)
driver.get("https://quotes.toscrape")
print(driver.title)
driver.quit()