Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- from base64 import b64decode
- from io import BytesIO
- from PIL import Image
- from httpx import AsyncClient
- from lxml.etree import HTML
- from more_itertools import first
- from pyppeteer import launch
- OCR_API = 'http://192.168.5.246:9898/ocr/file'
- async def resolve_captcha(b: bytes):
- async with AsyncClient() as client:
- resp = await client.post(OCR_API, files={'image': b})
- return resp.text
- async def main():
- browser = await launch(headless=True)
- page = await browser.newPage()
- await page.goto('http://192.168.5.203:3090/login')
- await asyncio.sleep(3)
- content = await page.content()
- html = HTML(content)
- src = first(html.xpath('//div[@class="login-code"]/img/@src'), None)
- if not src:
- return
- src = src.replace('data:image/jpeg;base64,', '')
- b = b64decode(src)
- img = Image.open(BytesIO(b))
- result = await resolve_captcha(b)
- pass
- if __name__ == '__main__':
- asyncio.run(main())
Add Comment
Please, Sign In to add comment