首页 > 解决方案 > Python, webkit2 gtk - 如何在 python 程序中使用 webkit 中的代理

问题描述

这是我迄今为止所拥有的一个简单的网络浏览器现在我希望使用代理加载页面。我检查了https://webkitgtk.org/reference/webkit2gtk/unstable/WebKitWebContext.html#webkit-web-context-set-network-proxy-settings但不明白如何实现这一点。

#!/usr/bin/python3

import gi
gi.require_version('Gtk', '3.0')
gi.require_version('WebKit2', '4.0')
from gi.repository import Gtk, WebKit2

class Window(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="Simple browser") # Name the app
        self.appWebView = WebKit2.WebView() # Added self to webkit view because it's good practice to assign variables to the class and not
        self.appWebView.load_uri("http://www.google.com")
        self.add(self.appWebView)

mainWindow = Window()
mainWindow.connect("delete-event", Gtk.main_quit) # This line quits the GTK loop when the window is closed
mainWindow.show_all() # Changed to mainWindow because Window is our class and mainWindow is our instance of the class that's running
Gtk.main()

希望有人可以通过示例帮助我如何做到这一点。非常感谢。

标签: pythonproxy

解决方案


推荐阅读