gpt4 book ai didi

python - Pygtk WebKit 获取源 html

转载 作者:行者123 更新时间:2023-12-02 21:26:08 24 4
gpt4 key购买 nike

这是我的示例代码。如何获取当前页面的html源代码。它只打印 'GString at 0x8875130' 。如何将其转换为真正包含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()

最佳答案

print x.str

数据可作为 GLib.String 对象的 .str 成员使用。有关更多详细信息,请在导入库后尝试在 python 提示符下使用 help(GLib.String)。

关于python - Pygtk WebKit 获取源 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24119290/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com