1. <i id='pgLtN'><tr id='pgLtN'><dt id='pgLtN'><q id='pgLtN'><span id='pgLtN'><b id='pgLtN'><form id='pgLtN'><ins id='pgLtN'></ins><ul id='pgLtN'></ul><sub id='pgLtN'></sub></form><legend id='pgLtN'></legend><bdo id='pgLtN'><pre id='pgLtN'><center id='pgLtN'></center></pre></bdo></b><th id='pgLtN'></th></span></q></dt></tr></i><div id='pgLtN'><tfoot id='pgLtN'></tfoot><dl id='pgLtN'><fieldset id='pgLtN'></fieldset></dl></div>

          <bdo id='pgLtN'></bdo><ul id='pgLtN'></ul>
        <legend id='pgLtN'><style id='pgLtN'><dir id='pgLtN'><q id='pgLtN'></q></dir></style></legend>
      2. <tfoot id='pgLtN'></tfoot>

        <small id='pgLtN'></small><noframes id='pgLtN'>

        如何在 selenium chromedriver 中使用经过身份验证的代

        时间:2023-10-08

        <small id='oapDl'></small><noframes id='oapDl'>

            <bdo id='oapDl'></bdo><ul id='oapDl'></ul>
            • <tfoot id='oapDl'></tfoot>

              <legend id='oapDl'><style id='oapDl'><dir id='oapDl'><q id='oapDl'></q></dir></style></legend>
              <i id='oapDl'><tr id='oapDl'><dt id='oapDl'><q id='oapDl'><span id='oapDl'><b id='oapDl'><form id='oapDl'><ins id='oapDl'></ins><ul id='oapDl'></ul><sub id='oapDl'></sub></form><legend id='oapDl'></legend><bdo id='oapDl'><pre id='oapDl'><center id='oapDl'></center></pre></bdo></b><th id='oapDl'></th></span></q></dt></tr></i><div id='oapDl'><tfoot id='oapDl'></tfoot><dl id='oapDl'><fieldset id='oapDl'></fieldset></dl></div>

                    <tbody id='oapDl'></tbody>
                1. 本文介绍了如何在 selenium chromedriver 中使用经过身份验证的代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  搜索了好几个小时后,我开始认为这是不可能的.

                  After searching for many hours I am starting to think this is impossible.

                  我需要为每次运行使用不同的经过身份验证的(非公共)代理通过 selenium 运行 Chrome.

                  I need to run Chrome through selenium using different authenticated (not public) proxy's for each run.

                  PROXY_IP = "<some IP address>"
                  UID = "<the user id>"
                  PWD = "<the password">
                  
                  options = webdriver.ChromeOptions()
                  options.add_argument("--proxy-server=%s:%s@%s" % (UID,PWD,PROXY_IP))
                  
                  driver = webdriver.Chrome(executable_path=".\driver\chromedriver.exe",
                                            chrome_options=options)
                  driver.get("<site URL>")
                  

                  Chrome 将启动并显示错误:

                  Chrome will fire-up and display the error:

                  This webpage is not available
                  ERR_NO_SUPPORTED_PROXIES
                  

                  如果我使用像这样不需要身份验证的公共代理...

                  If I use a public proxy requiring no authentication like this...

                  PROXY_IP = "<public proxy IP address>"
                  
                  options = webdriver.ChromeOptions()
                  options.add_argument("--proxy-server=%s" % PROXY_IP)
                  
                  driver = webdriver.Chrome(executable_path=".\driver\chromedriver.exe",
                                            chrome_options=options)
                  driver.get("<site URL>")
                  

                  ...它运行良好并在使用代理时显示站点.

                  ...it runs just fine and displays the site while using the proxy.

                  我还尝试了在用户 ID 前添加 http:// 的变体:

                  I also tried a variant with http:// in front of the user ID:

                  options.add_argument("--proxy-server=http://%s:%s@%s" % (UID,PWD,PROXY_IP))
                  

                  我进行了广泛的搜索,但没有找到解决方案,这让我相信根本不存在.

                  The fact that I have searched far and wide and haven't found a solution leads me to believe none might exist.

                  我确实找到了这个,但我无法理解它:

                  I did find this but I can't make sense out of it:

                  selenium chromedriver 身份验证代理

                  不确定 browswermob-proxy 是什么或应该做什么或如何在 Python 中实现和测试.除非绝对必要,否则我讨厌堆积创可贴解决方案.

                  Not sure what browswermob-proxy is or is supposed to do or how to implement and test in Python. I hate piling up band-aid solutions unless they are absolutely necessary.

                  编辑(21 年 11 月 8 日):

                  EDIT (08NOV21):

                  我已经多年不使用 Selenium 了.正因为如此,我现在缺乏上下文(和时间,对不起)来检查提供的较新答案并将一个标记为该问题的解决方案.SO 是否有一种机制可以用来有效地将这一职能委托给可能是该领域专业知识的当前从业者?

                  I have been away from using Selenium for many years. Because of this I now lack the context (and time, sorry) to go through the newer answers being provided and mark one as the solution to this problem. Does SO have a mechanism one could use to effectively delegate this function to someone who might be a current practitioner with expertise in this domain?

                  推荐答案

                  要在 python selenium 中使用带有身份验证的代理,您可以使用 硒线.

                  To use proxies with auth in python selenium you can use seleniumwire.

                  首先,使用 pip install selenium-wire

                  然后从 seleniumwire 导入 webdriver 而不是 selenium

                  Then import webdriver from seleniumwire instead selenium

                  from seleniumwire import webdriver
                  options = {
                      'proxy': {
                          'http': 'http://username:password@host:port', 
                          'https': 'https://username:password@host:port',
                          'no_proxy': 'localhost,127.0.0.1' # excludes
                      }
                  }
                  browser = webdriver.Chrome(path_to_driver, seleniumwire_options=options)
                  

                  现在您可以像使用 selenium 一样使用浏览器实例:browser.get('https://api.ipify.org') 等等...

                  Now you can use your browser instance exact the same way as selenium: browser.get('https://api.ipify.org') and so on...

                  这篇关于如何在 selenium chromedriver 中使用经过身份验证的代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 Selenium (Python) 中将打开的页面保存为 pd 下一篇:不支持直通,GL 被禁用

                  相关文章

                  最新文章

                  <tfoot id='vgDqB'></tfoot>

                      <i id='vgDqB'><tr id='vgDqB'><dt id='vgDqB'><q id='vgDqB'><span id='vgDqB'><b id='vgDqB'><form id='vgDqB'><ins id='vgDqB'></ins><ul id='vgDqB'></ul><sub id='vgDqB'></sub></form><legend id='vgDqB'></legend><bdo id='vgDqB'><pre id='vgDqB'><center id='vgDqB'></center></pre></bdo></b><th id='vgDqB'></th></span></q></dt></tr></i><div id='vgDqB'><tfoot id='vgDqB'></tfoot><dl id='vgDqB'><fieldset id='vgDqB'></fieldset></dl></div>

                    1. <legend id='vgDqB'><style id='vgDqB'><dir id='vgDqB'><q id='vgDqB'></q></dir></style></legend>

                      <small id='vgDqB'></small><noframes id='vgDqB'>

                      • <bdo id='vgDqB'></bdo><ul id='vgDqB'></ul>