帮助中心

   

热门搜索: 免费续期  推广  永久会员

python3取消代理操作代码

使用python来写爬虫程序,是多数爬虫工作者的选择,毕竟这款语言的操作性非常好,那么当我们设置完代理IP之后,爬虫完成我们又该怎么设置取消代理呢?

 

python3取消代理操作代码

 

python3需要在注册表设置取消IP代理服务,要怎么做?以下是具体代码:

 

import io, sys, time, re, os

import winreg

def enableProxy(IP, Port):

proxy = IP + “:” + str(Port)

xpath = “Software\Microsoft\Windows\CurrentVersion\Internet Settings”

try:

key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, xpath, 0, winreg.KEY_WRITE)

winreg.SetValueEx(key, “ProxyEnable”, 0, winreg.REG_DWORD, 1)

winreg.SetValueEx(key, “ProxyServer”, 0, winreg.REG_SZ, proxy)

except Exception as e:

print(“ERROR: ” + str(e.args))

finally:

None

def disableProxy():

proxy = “”

xpath = “Software\Microsoft\Windows\CurrentVersion\Internet Settings”

try:

key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, xpath, 0, winreg.KEY_WRITE)

winreg.SetValueEx(key, “ProxyEnable”, 0, winreg.REG_DWORD, 0)

winreg.SetValueEx(key, “ProxyServer”, 0, winreg.REG_SZ, proxy)

except Exception as e:

print(“ERROR: ” + str(e.args))

finally:

None

def main():

proxyIP = “10.10.1.2”

proxyPort = 123

try:

disableProxy() enableProxy(proxyIP, proxyPort)

except Exception as e:

print(“ERROR: ” + str(e.args))

finally:

pass

if __name__ == ‘__main__’:

main()

 

通过以上设置,就可以成功取消IE代理了。

关闭
19907977089
关注微信公众号,免费送30分钟时长