【问题标题】:How can I route my web browser through a proxy in python?如何通过 python 中的代理路由我的网络浏览器?
【发布时间】:2020-11-14 14:36:30
【问题描述】:

我正在寻找为 chrome 制作 VPN/代理类型的东西,我知道如何通过代理服务器发送请求并从中获取信息(urllib 或请求模块),但这对我来说并没有什么用处我正在尝试创建的内容。

我该怎么做呢?非常感谢任何帮助。

【问题讨论】:

  • 欢迎来到 StackOverflow。请花时间参加tour 并学习How to Ask。然后,您可以使用 minimal reproducible example 说明您的问题,以便人们可以帮助您编写迄今为止创建的代码。

标签: python proxy python-requests vpn traffic


【解决方案1】:

我不确定你在做什么,但你可以使用 Selenium 和代理来达到这个目的。

假设您使用Chrome webdriver,您的代码可能如下所示:

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

现在,如果您想在浏览器中执行某些操作,您可以手动执行,也可以使用 Selenium 自动执行,documentation here

【讨论】:

    【解决方案2】:

    好吧,我一直在寻找这个问题的答案已经有一段时间了,我没有发现任何特别的东西,但是如果你在 Windows 10 上,有代理设置,你可以用 python 更改它们但我不太确定。我能想到的其他选项是:使用 cmd 更改代理(您也可以从 python 中进行),我在 Stack Exchange 上找到了这篇文章:https://superuser.com/questions/709096/how-can-i-change-the-system-proxy-from-the-command-line/709103。但除此之外我不知道。

    【讨论】:

      猜你喜欢
      • 2011-10-06
      • 1970-01-01
      • 2017-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-30
      • 2014-04-30
      • 1970-01-01
      相关资源
      最近更新 更多