xtekky/TikTok-ViewBot

How to fix issue

Nikityyy opened this issue · 0 comments

#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