A Python script that scans barcodes using a webcam, interacts with a web form, and optionally saves the scanned data to a CSV file.
- Scans barcodes using a webcam.
- Automatically inputs the barcode data into a web form.
- Optionally saves the scanned barcode data to a CSV file.
- Submits the web form after scanning a barcode.
- Python 3.6+
- OpenCV
- pyzbar
- Selenium
- Google Chrome
- ChromeDriver
-
Clone the repository:
https://github.com/waldanzubary/scanner-barcode-.git
-
Install the required Python packages:
pip install opencv-python pyzbar selenium
-
Download and install Google Chrome:
-
Download ChromeDriver:
Make sure to download the version of ChromeDriver that matches your installed version of Google Chrome. Add the
chromedriver
executable to your system's PATH.
-
Start the local server: Ensure your web application is running locally on
http://127.0.0.1:8000
. -
Run the script:
python scanner.py
To save scanned barcode data to a CSV file, run the script with the
save_to_csv
argument set toTrue
:python barcode_scanner.py --save_to_csv True
-
Web Form URL: Modify the URL in the script to match the URL of the web form you want to interact with:
driver.get("http://127.0.0.1:8000/sales/create")
-
Web Form Input Element ID: Ensure the ID of the input element in the web form matches the ID used in the script:
input_element = driver.find_element(By.ID, "barcode_input")
-
Webcam not opening: Ensure your webcam is properly connected and not being used by another application.
-
ChromeDriver not found: Ensure ChromeDriver is installed and added to your system's PATH.
-
Barcode data not being entered into the form: Ensure the URL and input element ID in the script match those of your web form.