I'm trying to automate a web search via Python.
The website is behind hCaptcha
where I'm using 2captcha
solver.
Below I've replicate the same behavior as web browser does but I'm still being asked to re-solve the hCaptcha
again
Below is what i tried:
import httpximport triofrom twocaptcha import TwoCaptchaheaders = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0','Referer': 'https://iapps.courts.state.ny.us/nyscef/CaseSearch?TAB=courtDateRange','Origin': 'https://iapps.courts.state.ny.us'}API_KEY = 'hidden'async def solve_captcha(): solver = TwoCaptcha(API_KEY) return solver.hcaptcha( sitekey='600d5d8e-5e97-4059-9fd8-373c17f73d11', url='https://iapps.courts.state.ny.us/' )['code']async def main(): async with httpx.AsyncClient(base_url='https://iapps.courts.state.ny.us/nyscef/', headers=headers, follow_redirects=True) as client: r = await client.post('CaseSearch?TAB=courtDateRange') print('[*] - Solving CAPTCHA!') cap = await solve_captcha() print('[*] - CAPTCHA Solved') # Court: Chautauqua County Supreme Court data = {'selCountyCourt': '4667226','txtFilingDate': '02/14/2024','g-recaptcha-response': cap,'h-captcha-response': cap,'btnSubmit': 'Search', } r = await client.post('https://iapps.courts.state.ny.us/nyscef/CaseSearch?TAB=courtDateRange', data=data) with open('r.html', 'w') as f: f.write(r.text)if __name__ == "__main__": trio.run(main)