Please be aware of the following regarding captcha handling:
- Captcha v2: The login captcha might take a significant amount of time to complete, as it is v2.
- Text Captcha: This typically processes in no time.
If you encounter a captcha type that differs from what is described (for example, if text captcha appears instead of v2), you might need to adjust the captcha handling in your code:
- Swapping Captcha Handling: If there is a shift in captcha type, swap the lines of code relevant to captcha handling as necessary.
- Captcha v2 Site-Key: If you need to handle captcha v2 specifically, ensure you include the captcha v2 site-key. You can find this site-key by inspecting the element on the captcha page.
Make sure to update your implementation based on the current captcha type to ensure smooth functionality.
This Python script automates the process of logging into the BLS Italy Pakistan appointment system, checking for available appointments, and attempting to book one using the Playwright browser automation tool. The script is integrated with 2Captcha to solve both image-based CAPTCHAs and reCAPTCHA v2 challenges. It periodically refreshes the page to check for new appointment availability and tries to book an appointment when it becomes available.
- Login Automation: Automatically logs into the BLS Italy Pakistan website using the provided credentials.
- CAPTCHA Solving: Utilizes the 2Captcha API to solve both image-based CAPTCHAs and reCAPTCHA v2 challenges.
- Appointment Availability Check: Continuously monitors for available appointments for a specified date.
- Form Auto-fill: Automatically fills in required fields for appointment booking (location, appointment type, etc.).
- Error Handling and Retry: Handles timeouts, login issues, and pop-up windows with retries to maintain stability.
- Session Management: Automatically logs back in if the session expires or if the user is logged out.
- Python: Ensure Python 3.x is installed.
- Playwright: Install Playwright and set it up by running the following commands:
pip install playwright playwright install
- Pillow: Used for image handling in CAPTCHAs. Install it with:
pip install pillow
- Requests: Used for sending HTTP requests (to 2Captcha and for image downloads). Install with:
pip install requests
-
2Captcha API Key: Obtain a 2Captcha API key from 2Captcha and insert it into the script by replacing
'<************>'
in theAPI_KEY
variable. -
BLS Account Credentials: Update the placeholders
<EMAIL>
and<PASSWORD>
in thelogin
function with your BLS login credentials. -
Python Libraries: Ensure all required libraries are installed:
- Playwright
- Pillow
- Requests
-
Playwright Setup: Run the following to install the necessary browser binaries:
playwright install
- Ensure all dependencies are installed.
- Run the script from the terminal:
python play2.py
- solve_recaptcha_v2(): Uses 2Captcha to solve the reCAPTCHA v2 challenge and returns the solution to be used in the login process.
- solve_captcha(): Downloads the CAPTCHA image, sends it to 2Captcha, and returns the solution.
- login(): Automates the login process using the provided credentials and solved reCAPTCHA.
- check_appointment_date(): Checks if appointments are available for a specified date (11 September in this case).
- main(): The main control loop for logging in, navigating to the appointment page, checking appointment availability, and booking.
- The script checks if an appointment is available for 11 September. If you wish to change the date, modify the
check_appointment_date()
function accordingly. - Ensure the BLS account credentials and 2Captcha API key are correct and up-to-date in the script.
- The script runs in an infinite loop, checking for available appointments and refreshing the page regularly. To stop it, terminate the process manually.
This script is intended for educational purposes. Automating appointment booking may violate terms of service for certain websites. Use this script responsibly and at your own risk.