#ignore MS/DOS endings (on windows machines):
#config setup
git clone http://github.com/animesh/scripts
!. *.pdf *.asv *.csv *.txt *.history *swp *gz *tsv
This script uses Selenium to automatically log in to a website and submit a form using credentials and data from environment variables.
- Python 3.x
- Google Chrome browser
- ChromeDriver (matching your Chrome version)
selenium
Python package
-
Install dependencies:
pip install -r requirements.txt
-
Download ChromeDriver:
- Download from: https://sites.google.com/a/chromium.org/chromedriver/downloads
- Place the
chromedriver
binary in your PATH or specify its location with theCHROMEDRIVER_PATH
environment variable.
-
Set environment variables:
LOGIN_URL
: The URL of the login page.LOGIN_USERNAME
: Your username.LOGIN_PASSWORD
: Your password.FORM_FIELD_1
: Data for the form field (example; add more as needed).CHROMEDRIVER_PATH
: (Optional) Path to yourchromedriver
binary.
Example (Linux/macOS):
export LOGIN_URL='https://example.com/login' export LOGIN_USERNAME='your_username' export LOGIN_PASSWORD='your_password' export FORM_FIELD_1='your_form_data' export CHROMEDRIVER_PATH='/path/to/chromedriver'
Run the script:
python auto_login_form.py
- Update the field selectors in
auto_login_form.py
to match the actual names or XPaths of the login and form fields on your target website. - Add more environment variables and form fields as needed.
- The script runs Chrome in headless mode by default.
- For troubleshooting, remove the
--headless
option to see the browser window.