0
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()

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

4

1 回答 1

0

你会想这样称呼它:

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

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

于 2013-08-21T05:16:19.460 回答