Skip to content

Instantly share code, notes, and snippets.

@eXtizi
Created November 2, 2024 05:11
Show Gist options
  • Save eXtizi/6d5481c542500ac46715dbcd5aeb4fb3 to your computer and use it in GitHub Desktop.
Save eXtizi/6d5481c542500ac46715dbcd5aeb4fb3 to your computer and use it in GitHub Desktop.

Project Setup and Execution Guide

This README provides instructions on setting up a Python virtual environment, installing required packages, configuring ChromeDriver for Selenium, and running the script using pm2 or screen on a Linux system.

Prerequisites

Ensure you have the following installed on your system:

  • Python 3
  • pip (Python package installer)
  • Node.js and npm
  • pm2 (Node process manager)

Step 1: Install Python, Xvfb, and Node.js

Run the following commands to install Python3, Xvfb, Node.js, and npm:

sudo apt update
sudo apt install python3 python3-venv python3-pip xvfb nodejs npm -y

Step 2: Install pm2

Install pm2 globally to manage the process:

sudo npm install -g pm2

Step 3: Create a Virtual Environment

  1. Create a project directory (e.g., Main) and navigate into it:

    mkdir Main && cd Main
  2. Set up the virtual environment:

    python3 -m venv Main
  3. Activate the virtual environment:

    source Main/bin/activate

Step 4: Install Project Dependencies

Ensure your requirements.txt file is in the Main folder. Install dependencies with:

python -m pip install -r requirements.txt

ChromeDriver Setup for Selenium

Step 1: Check Your Chrome Version

Open Chrome and go to chrome://settings/help to find your version of Chrome (e.g., Chrome 115).

Step 2: Download ChromeDriver

  1. Go to the ChromeDriver download page.

  2. Download the version matching your Chrome version:

    wget https://chromedriver.storage.googleapis.com/<version>/chromedriver_linux64.zip

    Replace <version> with the ChromeDriver version (e.g., 115.0.5790.170).

  3. Extract the downloaded file:

    unzip chromedriver_linux64.zip
  4. Move ChromeDriver to a directory in your PATH:

    sudo mv chromedriver /usr/local/bin/
  5. Verify ChromeDriver is installed:

    chromedriver --version

Running the Python Script

Option 1: Using pm2 to Run the Script

To run the script with pm2 using xvfb:

pm2 start "xvfb-run -a python Main/seleniumV2.py" --name VFS

Managing pm2

  • List all processes: pm2 list
  • Restart the process: pm2 restart VFS
  • Stop the process: pm2 stop VFS
  • Delete the process: pm2 delete VFS
  • View logs: pm2 logs VFS

To enable pm2 startup on reboot:

pm2 startup
pm2 save

Option 2: Using screen to Run the Script

  1. Start a new screen session:

    screen -S VFS
  2. Run the script:

    source Main/bin/activate
    xvfb-run -a python Main/seleniumV2.py
  3. Detach from the screen session:

    • Press Ctrl + A, then D to detach without stopping the script.
  4. Reattach to the screen session:

    screen -r VFS
  5. Terminate the session:

    • Reattach to the session, stop the script, then type exit to close the screen session.

License

This project is licensed under the MIT License.


This `README.md` covers the setup, ChromeDriver installation, and execution options for both `pm2` and `screen`. Let me know if you need additional customization!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment