正在将https页加载到wx.html.HTMLWind

2024-06-02 09:16:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将https url加载到HTMLWindow中

import wx
import wx.html

class MyHtmlFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title, size=(600,400))
        html = wx.html.HtmlWindow(self)
        if "gtk2" in wx.PlatformInfo:
            html.SetStandardFonts()

        wx.CallAfter(html.LoadPage, "https://www.google.com")#Fails to load page 
        #but the following works ...
        #wx.CallAfter(html.LoadPage, "http://www.google.com")#Works Fine!


app = wx.PySimpleApp()
frm = MyHtmlFrame(None, "Simple HTML Browser")
frm.Show()
app.MainLoop()

有没有一种方法可以在HTMLWindow中加载ssl页面(或者其他在a-wxWindow中呈现ssl页面的方式)?在

我使用的是wx2.8.10,升级目前还不是一个真正的选择


Tags: httpsimportselftitleinithtmlwwwgoogle
2条回答

我真的很想把我的赏金给别人,但这真的是我的解决办法,我也。。。某种程度上。。。解决方案是使用wx IEWin

import wx
import wx.lib.iewin as iewin
class MyBrowser(wx.Dialog):
  def __init__(self, *args, **kwds):
    wx.Dialog.__init__(self, *args, **kwds)
    sizer = wx.BoxSizer(wx.VERTICAL)
    self.browser =  iewin.IEHtmlWindow(self)
    sizer.Add(self.browser, 1, wx.EXPAND, 10)
    self.SetSizer(sizer)
    self.SetSize((850, 730))
  def load(self,uri):
      self.browser.Navigate(uri)

if __name__ == '__main__':
  app = wx.App()
  dialog = MyBrowser(None, -1)
  dialog.browser.Navigate("https://www.google.com")
  dialog.Show()
  app.MainLoop()

您只需使用现有方法(如urllib2.urlopen)下载该文件,并将该文件保存到文件系统,然后将该文件名传递给HtmlWindow的LoadPage方法。在

下面的StackOverflow问题HTTPS connection Python How do I download a file over HTTP using Python?包含了现有方法的示例

其他更复杂的选项包括在下载或编译Python绑定之后使用wxIE和wxMozilla。在

相关问题 更多 >