1
votes

I haven't figured out how to install Chrome Driver for about 8 hours. I've done a lot of research and I've never tried one. Here is the contents of my Deployment package file: http://prntscr.com/o4kcjw I got quite a lot of errors when I tried it through the serverless CLI. How can I solve this problem?

I create and assign selenium, pymsql and chromedriver to Lambda with virtualenv. (Zipped) I have a python file inside my zipped file.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--window-size=960x900')

# Define browser driver
chrome_driver = '/chromedriver-Linux64.exe'
browser = webdriver.Chrome(executable_path=chrome_driver, chrome_options=chrome_options)

{ "errorMessage": "Message: 'chromedriver-Linux64.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home\n",
"errorType": "WebDriverException", "stackTrace": [ " File \"/var/lang/lib/python3.7/imp.py\", line 234, in load_module\n return load_source(name, filename, file)\n", " File \"/var/lang/lib/python3.7/imp.py\", line 171, in load_source\n module = _load(spec)\n", " File \"\", line 696, in _load\n", " File \"\", line 677, in _load_unlocked\n", " File \"\", line 728, in exec_module\n", " File \"\", line 219, in _call_with_frames_removed\n", " File \"/var/task/scraping.py\", line 16, in \n browser = webdriver.Chrome(executable_path=chrome_driver, chrome_options=chrome_options)\n", " File \"/var/task/selenium/webdriver/chrome/webdriver.py\", line 73, in init\n self.service.start()\n", " File \"/var/task/selenium/webdriver/common/service.py\", line 83, in start\n os.path.basename(self.path), self.start_error_message)\n" ] }

5

5 Answers

2
votes

AWS Lambda runs on linux. You have to download the linux chromedriver and the file name doesn't have .exe at the end. It should be just chromedriver

1
votes

Why arent you using the 'normal' chromedriver from https://www.seleniumhq.org/download/?

On windows this works for me:

driver = webdriver.Chrome(executable_path='D:/myPath/chromedriver.exe')

I installed my chromedriver, unzipped it and the path where I saved it, is 'D:/myPath/' (just an example)

0
votes

Say your directory structure looks something like this:

project
| main.py
| chromedriver-Linux64

You should have the chromedriver binary at the same level as your project files. Also, change the path pointing to the chromedriver binary from /chromedriver-Linux64.exe to ./chromedriver-Linux64.exe. The path you currently have looks for the binary in the root folder, rather than the current directory. The . means look in the directory this file is in.

0
votes

Write your path something like this

"C:\Users\arjun.bhardwaj\Downloads\drvr\chromedriver.exe

0
votes
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
#can use below if pip/sudo install webdriver_manager
from webdriver_manager.chrome import ChromeDriverManager

chrome_options = Options()
chrome_options.add_argument('--headless')
#this below not really required if using --headless`enter code here`
chrome_options.add_argument('--window-size=960x900') 
# You can use the below to run
browser = webdriver.Chrome(executable_path=ChromeDriverManager().install(), chrome_options=chrome_options)
browser.get('https://www.google.com/')