Pandaaaa906

Untitled

May 10th, 2023 (edited)
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. import asyncio
  2. from base64 import b64decode
  3. from io import BytesIO
  4.  
  5. from PIL import Image
  6. from httpx import AsyncClient
  7. from lxml.etree import HTML
  8. from more_itertools import first
  9. from pyppeteer import launch
  10.  
  11. OCR_API = 'http://192.168.5.246:9898/ocr/file'
  12.  
  13.  
  14. async def resolve_captcha(b: bytes):
  15.     async with AsyncClient() as client:
  16.         resp = await client.post(OCR_API, files={'image': b})
  17.         return resp.text
  18.    
  19.  
  20. async def main():
  21.     browser = await launch(headless=True)
  22.     page = await browser.newPage()
  23.     await page.goto('http://192.168.5.203:3090/login')
  24.     await asyncio.sleep(3)
  25.     content = await page.content()
  26.     html = HTML(content)
  27.     src = first(html.xpath('//div[@class="login-code"]/img/@src'), None)
  28.     if not src:
  29.         return
  30.     src = src.replace('data:image/jpeg;base64,', '')
  31.     b = b64decode(src)
  32.     img = Image.open(BytesIO(b))
  33.     result = await resolve_captcha(b)
  34.     pass
  35.  
  36.  
  37. if __name__ == '__main__':
  38.     asyncio.run(main())
  39.  
Add Comment
Please, Sign In to add comment