camzay
camzay

Reputation: 1

How can I route my web browser through a proxy in python?

I'm looking to make a VPN/proxy type thing for chrome, I know how to send requests through a proxy server and get the information from it (urllib, or requests module) but that's not really any use to me for what I'm trying to create.

How could I go about doing this? Any help is appreciated massively.

Upvotes: 0

Views: 3118

Answers (2)

ツTruePvP
ツTruePvP

Reputation: 13

Well i've been looking for an answer on this question for quite a while now, i haven't found anything in particular, but if you're on windows 10 there are proxy settings and you can maybe change them with python but im not quite sure. Other option i can think of is: change proxies with cmd(you can also do it from python too), i found this post on Stack Exchange: https://superuser.com/questions/709096/how-can-i-change-the-system-proxy-from-the-command-line/709103. But other than that i have no idea.

Upvotes: 1

Matas Minelga
Matas Minelga

Reputation: 70

I'm not sure exactly what you're doing, but you could use Selenium with a proxy for this purpose.

If let's say you use Chrome webdriver, your code could look something like this:

from selenium import webdriver


PROXY = "11.11.11.11:1234" # IP:PORT or HOST:PORT

options = webdriver.ChromeOptions()
options.add_argument('--proxy-server=%s' % PROXY)

driver = webdriver.Chrome(
    executable_path='chromedriver', options=options # The path of your downloaded webdriver here
)

browser.get('https://google.com')  # Opens url in a selenium browser

Now if you want to do something in the browser, you can either do it manually or automatically using Selenium, documentation here

Upvotes: 0

Related Questions