These are archived pages, most of them date back to 2007-2012. This content might not be relevant or accurate anymore.

WebKit snippets (Gtk+)

These snippets show how to use WebKit bindings in Python and Ruby.

import gtk, webkit

import gobject
gobject.threads_init()

view = webkit.WebView()

# don't load images, we're not visible

s = view.get_settings()
s.set_property('auto-load-images', False)

w = gtk.Window()
w.add(view)
#w.show_all()

view.open('URL here')

# how to get HTML

def get_page(webview):
    # or use get_main_frame.get_data_source.get_data (since webkit 1.1.14)
    webview.execute_script("document.title=document.documentElement.innerHTML;")
    html = webview.get_main_frame().get_title()
    webview.execute_script("document.title='';")
    return html

def handler(webview, webframe):
    # do your stuff and quit, it's up to you to do handle multiple submits
    # webview.execute_script("javascript here")
    gtk.main_quit()

view.connect('load-finished', handler)
gtk.main()

Or similarly in Ruby (please note that saving page might not be implemented in rbwebkitgtk yet, quick patch – :howto:webframe.patch, it does not implement WebSettings either):

require 'gtk2'
require 'webkit'

view = Gtk::WebKit::WebView.new
Gtk::Window.new.add(view)#.show_all

view.open('URL here')

# how to get HTML

def get_page(webview)
  # or use get_main_frame.get_data_source.get_data (since webkit 1.1.14)
  webview.execute_script("document.title=document.documentElement.innerHTML;")
  html = webview.get_main_frame.get_title
  webview.execute_script("document.title='';")
  return html
end

view.signal_connect('load-finished') { |webview, webframe|
  # do your stuff and quit, it's up to you to do handle multiple submits
  # webview.execute_script("javascript here")
  Gtk.main_quit
}

Gtk.main
 
 
 
disorder's homepage