如何在cefpython中获取当前网址?

时间:2018-09-30 03:40:05

标签: python cefpython

我应该如何在Cefpython3中加载当前URL? 这是我的当前代码:

from cefpython3 import cefpython as cef
import platform
import sys

url = "https://google.com/"

def main():
    check_versions()
    sys.excepthook = cef.ExceptHook
    cef.Initialize()
    cef.CreateBrowserSync(url=url,
                          window_title="browser")
    cef.MessageLoop()
    cef.Shutdown()

def geturl():
    cef.getURL()
geturl()

def check_versions():
    ver = cef.GetVersion()
    print("[hello_world.py] CEF Python {ver}".format(ver=ver["version"]))
    print("[hello_world.py] Chromium {ver}".format(ver=ver["chrome_version"]))
    print("[hello_world.py] CEF {ver}".format(ver=ver["cef_version"]))
    print("[hello_world.py] Python {ver} {arch}".format(
           ver=platform.python_version(),
           arch=platform.architecture()[0]))
    assert cef.__version__ >= "57.0", "CEF Python v57.0+ required to run this"


if __name__ == '__main__':
    main()

由于Cef的所有版本,我无法找到答案。

1 个答案:

答案 0 :(得分:0)

cef.CreateBrowserSync函数返回一个具有Browser方法的GetUrl对象。例如,您可以将该对象存储为全局变量,并在以后随时访问。请参阅cefpython API文档以获取参考。