2014-06-09 1 views
0

여기 내 샘플 코드입니다. 현재 페이지의 html 소스 코드를 얻으려면 어떻게해야합니까? 'GString at 0x8875130'만 출력합니다. 어떻게 그것을 실제 텍스트로 변환 HTML이 포함되어 있습니까?Pygtk WebKit get source 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() 

답변

0
print x.str 

데이터 객체 GLib.String .str의 부재로서 사용할 수있다. 자세한 내용은 라이브러리를 가져온 후 파이썬 프롬프트에서 도움말 (GLib.String)을 사용하십시오.

+0

굉장합니다. 감사 – Nitheesh

0

이 방법은 저에게 효과적입니다.

#!/usr/bin/env python 
import webkit, gtk 

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

win = gtk.Window() 
win.set_position(gtk.WIN_POS_CENTER_ALWAYS) 
win.resize(1024,768) 
win.connect('destroy', lambda w: gtk.main_quit()) 
win.set_title('Titulo') 
vbox = gtk.VBox(spacing=5) 
vbox.set_border_width(5) 
web = webkit.WebView() 
vbox.pack_start(web, fill=True, expand=True) 

web = webkit.WebView() 
web.open("http://www.google.co.ve") 
web.connect("load-finished", get_source) 

browser_settings = web.get_settings() 
browser_settings.set_property('user-agent', 'Mozilla/5.0 (X11; Linux i586; rv:31.0) Gecko/20100101 Firefox/31.0') 
browser_settings.set_property('enable-default-context-menu', True) 
browser_settings.set_property('enable-accelerated-compositing', True) 
browser_settings.set_property('enable-file-access-from-file-uris', True) 
web.set_settings(browser_settings) 

win.add(web) 
win.show_all() 
gtk.main()