Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to fix issue #188

Open
Nikityyy opened this issue Jan 29, 2024 · 0 comments
Open

How to fix issue #188

Nikityyy opened this issue Jan 29, 2024 · 0 comments

Comments

@Nikityyy
Copy link

Nikityyy commented Jan 29, 2024

#INSTALL TESSERACT OCR
#pip install pytesseract

import pytesseract
import base64
from json.decoder import JSONDecodeError
from PIL import Image
    
    def solve(debug) -> dict:

        session = Session()
        session.headers = {
                'authority': 'zefoy.com',
                'origin': 'https://zefoy.com',
                'authority': 'zefoy.com',
                'cp-extension-installed': 'Yes',
                'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
            }
        
        while True:
            source_code = str(session.get('https://zefoy.com').text).replace('&', '&')
            captcha_token = findall(r'<input type="hidden" name="(.*)">', source_code)
            
            if 'token' in captcha_token:
                captcha_token.remove('token')
                
            captcha_url    = findall(r'img src="([^"]*)"', source_code)[0]
            token_answer = findall(r'type="text" name="(.*)" oninput="this.value', source_code)[0]
            encoded_image = b64encode(BytesIO(session.get('https://zefoy.com' + captcha_url).content).read()).decode('utf-8')
            try:
                image_data = base64.b64decode(encoded_image)
    
                image = Image.open(BytesIO(image_data))
                
                captcha_answer = pytesseract.image_to_string(image)
            except JSONDecodeError as e:
                print(f"Error decoding JSON from the server response. Response content: {e.doc}")
                sleep(1)
                continue
            
            sleep(1)

            data = {
                token_answer: captcha_answer,
            }

            for values in captcha_token:
                token, value = values.split('" value="')
                data[token] = value
            else:
                data['token'] = ''

            response = session.post('https://zefoy.com', data = data).text
            try:
                findall(r'remove-spaces" name="(.*)" placeholder', response)[0]
                return {'name':'PHPSESSID', 'value': session.cookies.get('PHPSESSID')}
            except:
                pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant