Hi, In this post I briefly explain how to setup chrome driver on Kali linux, to use with selenium for web scraping. First, you need to have Chrome browser installed on Kali. Next, you can download the chrome driver match with the browser version and setup on python selenium scripts.
Step 1: Install Chrome Browser
The following steps are to install chrome browser version 80.0.3987.106 (Official Build) (64-bit). Reference: https://computingforgeeks.com/install-google-chrome-browser-on-kali-linux/
sudo apt update
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install ./google-chrome-stable_current_amd64.deb
cat /etc/apt/sources.list.d/google-chrome.list
google-chrome-stable --no-sandbox
Update:
On Kali 2020.1 use following commands: Since Kali 2020.1 supports non-root user, it is not required to use –no-sandbox option. If you are using root user account, then again have to use –no-sandbox option.
sudo apt updatewget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install ./google-chrome-stable_current_amd64.deb
google-chrome-stable
Step 2: Download Chrome Driver
Next, visit the web site https://chromedriver.chromium.org/downloads and download the linux_64 zipped version of ChromeDriver 80.0.3987.106. You can optionally move the driver file to /usr/bin/ folder.
chmod +x '/home/python tool/chromedriver_linux64/chromedriver' sudo mv -f '/home/python tool/chromedriver_linux64/chromedriver' /usr/bin/chromedriver
Step 3: Setup Chrome Driver inside python script
In the python script you should specify the location of the chrome driver, as well as configure options to have chrome driver working with selenium.
from selenium.webdriver.chrome.options import Options
chrome_options = Options() chrome_options.add_argument('--headless') chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-dev-shm-usage') driver = webdriver.Chrome('/usr/bin/chromedriver', chrome_options=chrome_options) driver.get(URL)
Alternatively Can Use Firfox (Kali Linux includes Firfox Browser by default):
Download the firfox driver match with the browser version from https://github.com/mozilla/geckodriver/releases e.g., for browser versions >=60, driver version 26
geckodriver-v0.26.0-linux64.tar.gz
from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities cap = DesiredCapabilities().FIREFOX cap["marionette"] = False browser = webdriver.Firefox(capabilities=cap, executable_path=r'/root/Tools/Firefox/geckodriver')
Cheers ! 🙂