python修改widows系统代理,爬虫
2021/6/18 9:27:20
本文主要是介绍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")
这篇关于python修改widows系统代理,爬虫的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-25Python编程基础:变量与类型
- 2024-11-25Python编程基础与实践
- 2024-11-24Python编程基础详解
- 2024-11-21Python编程基础教程
- 2024-11-20Python编程基础与实践
- 2024-11-20Python编程基础与高级应用
- 2024-11-19Python 基础编程教程
- 2024-11-19Python基础入门教程
- 2024-11-17在FastAPI项目中添加一个生产级别的数据库——本地环境搭建指南
- 2024-11-16`PyMuPDF4LLM`:提取PDF数据的神器