This script is designed to fetch PAN details from the Inland Revenue Department (IRD) of Nepal using the PAN number. It performs the following steps:
Solves the CAPTCHA. Uses the token, CAPTCHA, and PAN number to fetch the PAN details.
Python 3.x
requests
library
You can install the required library using pip:
pip install requests
To run the script, execute the following command:
python script_name.py
Replace script_name.py with the actual name of your Python file.
python ird_pan_search.py
The script logs the process and results to both the console and a log file named search_pan.log.
IRD
Class
def __init__(self, pan_no: int):
Initializes the IRD class with the provided PAN number. Retrieves the CAPTCHA, token, and cookies.
def _get_captcha_and_cookie(self) -> Tuple[str, int, Dict[str, str]]:
Connects to the IRD PAN search page, retrieves and solves the CAPTCHA, extracts the token and cookies.
def get_pan_details(self) -> Optional[Dict[str, Any]]:
Uses the retrieved token, CAPTCHA, and cookies to fetch the PAN details from the IRD website.
Logs are configured to output to both the console and a file named search_pan.log. Logging provides details about each step and any errors encountered.
Here's a snippet showing how to use the IRD class:
if __name__ == '__main__':
try:
ird_instance = IRD(pan_no=111111111)
pan_details = ird_instance.get_pan_details()
if pan_details:
logger.info(f"PAN details: {pan_details}")
else:
logger.warning("PAN details could not be retrieved.")
except Exception as e:
logger.error(f"An error occurred: {e}")
Replace 111111111 with the actual PAN number you want to search for.
- The script handles HTTP request errors and logs appropriate messages.
- If the CAPTCHA or token cannot be found in the response, an error is logged and an exception is raised.
- If the response from the IRD server is invalid or empty, an appropriate warning is logged.
This project is licensed under the MIT License.