duhow / hass-aigues-barcelona

Custom component for Home Assistant to integrate data from Aigues de Barcelona
GNU General Public License v3.0
52 stars 6 forks source link

Posible captcha response? #25

Open mrbluebrett opened 2 weeks ago

mrbluebrett commented 2 weeks ago

Encontré este codigo para resolver el recaptcha de google:

https://github.com/Hartman5/recaptchaV3-Bypass/blob/main/index.js

Podria servir no? Intentare a ver si se adaptarlo a python, pero si le quieres echar un ojo aqui tienes...

aritztg commented 2 weeks ago

Con un poco de copilot y algún retoque, esto podría ser un punto de partida:

import re
import requests

anchor_url = 'PUT ANCHOR URL HERE'
url_base = 'https://www.google.com/recaptcha/'
re_pattern = re.compile(r'([api2|enterprise]+)/anchor\?(.*)')
matches = re_pattern.search(anchor_url)
url_base += matches.group(0) + '/'
params = matches.group(1)

response = requests.get(
    url_base + 'anchor',
    headers={'content-type': 'application/x-www-form-urlencoded'},
    params={'params': params}.  # Check this!
)

if response.status_code == 200:
    re_token = re.compile(r'"recaptcha-token" value="(.*?)"')
    token = re_token.search(response.text).group(1)
    params2 = ""
    for pair in params.split('&'):
        params2 += pair.split('=')

    post_data = params2['v'] + token + params2['k'] + params2['co']
    re_key = re.compile(r'value="(.*?)"')
    key = re_key.search(post_data).group(1)
    print(key)
else:
    print(f"Error: {response.status_code}")