简体   繁体   中英

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM