Skip to content

Instantly share code, notes, and snippets.

@pioz
Created October 27, 2011 00:43
Show Gist options
  • Select an option

  • Save pioz/1318460 to your computer and use it in GitHub Desktop.

Select an option

Save pioz/1318460 to your computer and use it in GitHub Desktop.
Use QT and Webkit to manipulate the DOM
require 'Qt'
require 'qtwebkit'
class Viewer < Qt::WebView
slots 'change_h1()'
def initialize(parent = nil)
super(parent)
connect(self, SIGNAL('loadFinished(bool)'), self, SLOT('change_h1()'))
end
def change_h1
document = page.mainFrame.documentElement
document.findFirst('h1').setPlainText('Fuck Yeah')
document.findFirst('img.avatar').setAttribute('src', 'http://3.bp.blogspot.com/_4-k4YH3MeeE/TSpkNodQS5I/AAAAAAAAAhY/lvehzszHOuM/s400/fuck_yeah_.jpg')
end
end
a = Qt::Application.new(ARGV)
v = Viewer.new
v.load Qt::Url.new('http://www.pioz.it/')
v.show
a.exec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment