pythonwebpython-requestsrecaptchapywebview

Rendering reCaptcha on python Http Requests


I am not really sure how can I use the HTTP Requests 's response to show the widget.

The problem is that when I am requesting GET in http link and it returns a html response; but when I try to render the html part of where the widget is, the pywebview throws off error like

A Server error occurred. Please contact the administrator.

Or it shows the values of the html's tag not the html webview itself

Code for reference:

def handle_captcha(sess, request, ua):
    http_response = sess.get(request, headers=ua)
    http_show_captcha = BeautifulSoup(http_response.text, 'html.parser')
    print("hellos")
    window = webview.create_window('Captcha', http_show_captcha.find('div' , attrs={"class" : "checkpoint__wrapper content"}).text)
    webview.start()

The flow of this program is to access website through http request -> manually solve the captcha -> get the captcha's response -> target page

My question here is, is there any python framework that renders HTTP response especially the reCaptcha Widget? Or what is the best way to handle this problem? And how can I store the session inside the webview's response, or how can I access the previous session that was generated from http request?


Solution

  • If you ever stumbled upon this question. I have already solved this a week ago.

    The solution I used is to run a custom JS script using Pywebview:

    Question #1 Is there any python framework that renders HTTP response especially the Captcha widget?

    Answer: You have to do it by yourself.

    Question #2 What's the best way to handle this problem?

    Answer: Fetch the widget's location then manually load it to webview. Then after that just get the payload using JS: window.evaluate_js("document.querySelector('#g-recaptcha-response').value")

    Question #3 How can I store the session to webview response?

    Answer: You can't. But maybe you can inject the session using the pywebview's API.

    Question #4 How can I access the previous session that was generated from HTTP Request.

    Answer: This is almost same as the question #3. Maybe we can just fetch the session manually then store it to the pywebview's API.

    Hope anyone helps this.