【问题标题】:python pygtk webview rendering downloaded html codepython pygtk webview渲染下载的html代码
【发布时间】:2013-08-19 07:44:53
【问题描述】:
import pycurl
from StringIO import StringIO
import gtk
import webkit

wd = gtk.Window()
wd.set_title("example browser")

storage = StringIO()
c=pycurl.Curl()
c.setopt(pycurl.ENCODING,"")
c.setopt(pycurl.FOLLOWLOCATION,1)
c.setopt(pycurl.AUTOREFERER,1)
c.setopt(pycurl.HEADER,1)
c.setopt(pycurl.MAXREDIRS,5)
c.setopt(pycurl.FAILONERROR,1)
c.setopt(pycurl.URL,"http://whatsmyua.com")
c.setopt(pycurl.WRITEFUNCTION, storage.write)
c.perform()
c.close()

html1 = storage.getvalue()
htm = webkit.WebView()

htm.load_string("<p>example page</p><br>" , "text/html" , "utf-8" , html1)

wd.add(htm)
wd.show_all()
gtk.main()

上面的代码下载页面,然后显示一个只包含“示例页面”字符串而没有其他内容的窗口。所以我该怎么做 。请帮忙......

【问题讨论】:

  • 为什么使用pycurl?这与使用台式磨石擦鞋一样容易使用;你很可能会受伤..

标签: python webkit pygtk pycurl


【解决方案1】:

你会想这样称呼它:

htm.load_string(html1, 'text/html', 'utf-8', 'file://')

最后一个参数是文档中相对链接的基本 URI。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多