from bs4 import BeautifulSoup import requests import pytesseract as loki url = "https://services.ecourts.gov.in/ecourtindia_v6/" with requests.Session() as s: r = s.post(url) r = s.post( url+"vendor/securimage/securimage_show.php?f1c86df619238773796a9fa5a02672d5") soup = BeautifulSoup(r.text, "html5lib") imgs = soup.findAll('img', {'id': 'captcha_image'}) captcha_path = r"C:\\Users\\luyna\\Downloads\\captcha.png" # save captcha with open(captcha_path, 'wb') as f: for chunk in r: f.write(chunk) captcha_text = loki.image_to_string( captcha_path, config='--psm 10 --oem 3 -c tessedit_char_whitelist=0123456789abcdefghijklmnopqrstuvwxyz') r = s.post(url, data={"cino": "mhcc020200552019", "fcaptcha_code": captcha_text}) r = s.get(url) soup = BeautifulSoup(r.content, "lxml") if "MHCC020200552019" in soup: print(soup)