xtekky / TikTok-ViewBot

ViewBot using requests | Fast, no selenium | Custom Views count and clean Design
https://t.me/onlpx
Apache License 2.0
1.17k stars 468 forks source link

How to fix issue #188

Open Nikityyy opened 5 months ago

Nikityyy commented 5 months ago

#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