Change browser proxy settings from Python?

后端 未结 2 1000
别跟我提以往
别跟我提以往 2020-12-25 09:16

I have written a program that relies on a proxy to function. I now need a script that will check to see if the browser is set to use the right proxy, and if not, change it t

2条回答
  •  感动是毒
    2020-12-25 10:14

    Much thanks to @Cesar Canassa, but there is a small problem, you should always refresh after you change the setting, otherwise the changes you just made in winreg will be discarded when you refresh. So it should be like this.

    import ctypes
    
    INTERNET_OPTION_REFRESH = 37
    INTERNET_OPTION_SETTINGS_CHANGED = 39
    
    internet_set_option = ctypes.windll.Wininet.InternetSetOptionW
    
    internet_set_option(0, INTERNET_OPTION_SETTINGS_CHANGED, 0, 0)
    internet_set_option(0, INTERNET_OPTION_REFRESH, 0, 0)
    

提交回复
热议问题