D
D
dvomaks2016-09-15 00:36:35
Webkit
dvomaks, 2016-09-15 00:36:35

How to access iframe on foreign domain in python+webkit?

Let's start with the python code itself:

from gi.repository import Gtk,WebKit
import json

def load_finished(webview, frame):
    js = 'alert("a");'
    js2 = """ 
        var iframe = document.querySelector('iframe');
        console.log(iframe.contentWindow.document);
    """
    v.execute_script(js2)
    

w = Gtk.Window()
v = WebKit.WebView()
v.connect("load-finished", load_finished)

sw = Gtk.ScrolledWindow()

w.add(sw)
sw.add(v)
w.set_size_request(500,700)

v.load_html_string("""
<!doctype html>
<html>
<head>
<title>A demo</title>
</head>
<body>
<script src="//www.google.com/recaptcha/api.js"></script>
<div id="gr" class="g-recaptcha" data-sitekey="6LdbCR0TAAAAAGRU12rA3iBsS5AVRh5rbYAY1TPX"></div>
</body>
</html>
""", "http://bigclaim.ru")

w.show_all()
Gtk.main()

The bottom line is that the recaptcha is loaded in the window, which is tied to the domain. How can I access the contents of the iframe that is generated by the recaptcha script. That is, you need to use js to click on the button, select the necessary elements, etc.
In this embodiment, it displays in the console

** Message: console message: @3: TypeError: null is not an object (evaluating 'iframe.contentWindow') **
Message: console message: @0: Blocked a frame with origin " bigclaim.ru " from accessing a frame with origin " https://www.google.com ". The frame requesting access has a protocol of "http", the frame being accessed has a protocol of "https". Protocols must match.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rou1997, 2016-09-15
@Rou1997

Instead of WebKit, use Phantom.js or Selenium, both support cross-domain access to frames, or you can also install Spartan, it is cross-platform, I work with it on Ubuntu 14.04, it (Edge) is a fundamentally new "engine", which consists of the original Trident code, completely rewritten in .NET, so I run it from under Mono, I even installed Mono in a lighter in a piezoelectric element and the Spartan browser works there, and it is interesting in that it is 100% compatible with Trident from which it does not borrow not a line of code, thanks to this it has the same "fancy" DOM ​​and BOM APIs as in IE, they are very convenient and violate any policies.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question