Created
October 27, 2011 00:43
-
-
Save pioz/1318460 to your computer and use it in GitHub Desktop.
Use QT and Webkit to manipulate the DOM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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