python修改widows系统代理,爬虫
作者:互联网
import winreg def edit_system_proxy(open_or_close, host, port): """ 修改系统代理函数 :param open_or_close: 是否开启 bool :param host: IP :param port: 端口 :return: """ proxy = f"{host}:{port}" root = winreg.HKEY_CURRENT_USER proxy_path = r"Software\Microsoft\Windows\CurrentVersion\Internet Settings" kv_Enable = [ (proxy_path, "ProxyEnable", 1, winreg.REG_DWORD), (proxy_path, "ProxyServer", proxy, winreg.REG_SZ), ] kv_Disable = [ (proxy_path, "ProxyEnable", 0, winreg.REG_DWORD), # (proxy_path, "ProxyServer", proxy, winreg.REG_SZ), ] if open_or_close: kv = kv_Enable else: kv = kv_Disable for keypath, value_name, value, value_type in kv: hKey = winreg.CreateKey(root, keypath) winreg.SetValueEx(hKey, value_name, 0, value_type, value) if __name__ == '__main__': edit_system_proxy(False, "127.0.0.1", "8848")
标签:__,winreg,python,爬虫,value,kv,path,widows,proxy 来源: https://www.cnblogs.com/longwenzhang/p/14897970.html