#!/usr/bin/env python3 import gi gi.require_version("WebKit", "1.0") from gi.repository import WebKit, Gtk, GObject WebKit.init_python() import pywebkit def on_destroy(wnd): Gtk.main_quit() def on_click(event): print('button click ', event) def on_load_finished(webview, webframe): print('Load finished ({})'.format(webview.get_uri())) doc = pywebkit.GetDomDocument(webview) links = doc.getElementsByTagName('a') print('Links count: {}'.format(len(links))) for i, a in enumerate(links): print('\t{}) {}'.format(i+1, a.getAttribute('href'))) button = doc.createElement('button') button.innerText = 'Click Me' button.onclick = on_click body = doc.getElementsByTagName('body')[0] body.appendChild(button)