Search code examples
pythonhtmlwebkitpygtkgtk3

Pygtk WebKit get source html


Here is my sample code. How do I get the html source code of the current page. It only prints 'GString at 0x8875130' . How to convert it to real text contains html?

from gi.repository import WebKit
from gi.repository import Gtk, Gdk

def get_source(webobj, frame):
    print "loading..."
    x = web.get_main_frame().get_data_source().get_data()
    print x

win = Gtk.Window()

web = WebKit.WebView()
web.open("http://google.com")
web.connect("load-finished", get_source)

win.add(web)

win.show_all()

Gtk.main()

Solution

  • print x.str
    

    Data is available as .str member of GLib.String object. For further details try help(GLib.String) on python prompt after importing libraries.