开发者

wx.webkit -- how to get current URL...?

开发者 https://www.devze.com 2023-03-05 01:23 出处:网络
I am trying to build a custom browser using wx.webkit. The following code works cleanly. I want to get the current URL of the page that is being currently displayed. Using the GetPageURL() method doe

I am trying to build a custom browser using wx.webkit. The following code works cleanly.

I want to get the current URL of the page that is being currently displayed. Using the GetPageURL() method does not seem to help. This always displays the starting URL (http://www.google.com in this case). It does not seem to get updated.

How can i get the updated URL when i navigate from one page to another...?

import wx
import wx.webkit

class wxBrowser(wx.Frame):
  def __init__(self, parent, id, title):
    wx.Frame.__init__(self, parent, id, title, size=(800, 625))

    self.browser = wx.webkit.WebKitCtrl(self,-1) 
    self.browser.LoadURL('http://www.google.com')
    self.browser.Bind(wx.EVT_KEY_DOWN, self.PrintURL)
    self.Centre()
    self.Show(True)

  def PrintURL(self, event):
    # show current URL on Cmd P
    if event.CmdDown() and event.GetKeyCode() == 80:
        print self.browser.Get开发者_Python百科PageURL()

if __name__ == '__main__':
  app = wx.App()
  wxBrowser(None, -1, 'My Browser')
  app.MainLoop()


Use a wx.html2.WebView.New widget instead.


There is a get_uri() method. You have to use it like this

browser = webkit.WebView()
browser.open("http://example.com")
print browser.get_main_frame().get_uri()
0

精彩评论

暂无评论...
验证码 换一张
取 消