+ 2

What is the easiest way to set a proxy in python (chrome)?

In these days I have searched to change the proxy settings while I'm opening an incognito mode page with webbrowser module. I have found the selenium module that can let you to do that, but it's quite difficult to set and it has given me problem when I tried (like permissions and paths). And also to use selenium you have to install "chromewebdriver.exe" from thier web page, and it's so annoying 'cause I have to install my .py script on many comptuers. So I'm asking if there's method in webbrowser to do that, and else if what the easiest way to set a proxy in python?

28th Feb 2019, 6:56 AM
Giordano Fratti
Giordano Fratti - avatar
3 Respuestas
+ 3
For Linux & Mac you can set proxy settings in your bash_profile or bashrc file, these would be globally set for your OS and you can write a script that sets and unsets the proxy settings. For Windows I am sure you can do the same thing in CMD or powershell
1st Mar 2019, 3:22 AM
Steven M
Steven M - avatar
+ 3
Oh thanks, I'm searching now :))) I will advice when I find an example (I forgot to mention that I'm on Windows)
1st Mar 2019, 5:55 AM
Giordano Fratti
Giordano Fratti - avatar
+ 2
import os, webbrowser def proxy(proxyserveraddress, proxyport): os.system('reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d ' + proxyserveraddress + ':' + proxyport + ' /f') os.system('reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f') proxy("212.237.56.83", "8080") url = "http://met.bz/bjL3Vje" chrome_path = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s --incognito" webbrowser.get(chrome_path).open(url) That's the code that now I use It works very well, Thanks Steven
2nd Mar 2019, 9:24 AM
Giordano Fratti
Giordano Fratti - avatar