久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <legend id='BkylD'><style id='BkylD'><dir id='BkylD'><q id='BkylD'></q></dir></style></legend>
    • <bdo id='BkylD'></bdo><ul id='BkylD'></ul>

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

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

    2. 通過 Selenium chromedriver 進行 Python 代理身份驗證

      Python proxy authentication through Selenium chromedriver(通過 Selenium chromedriver 進行 Python 代理身份驗證)
      <i id='RY42f'><tr id='RY42f'><dt id='RY42f'><q id='RY42f'><span id='RY42f'><b id='RY42f'><form id='RY42f'><ins id='RY42f'></ins><ul id='RY42f'></ul><sub id='RY42f'></sub></form><legend id='RY42f'></legend><bdo id='RY42f'><pre id='RY42f'><center id='RY42f'></center></pre></bdo></b><th id='RY42f'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='RY42f'><tfoot id='RY42f'></tfoot><dl id='RY42f'><fieldset id='RY42f'></fieldset></dl></div>
      • <small id='RY42f'></small><noframes id='RY42f'>

          <bdo id='RY42f'></bdo><ul id='RY42f'></ul>
          <tfoot id='RY42f'></tfoot>

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

                  <tbody id='RY42f'></tbody>
              1. 本文介紹了通過 Selenium chromedriver 進行 Python 代理身份驗證的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                We tried for a few days to setup Proxy Authentication with selenium chromedriver in Python. We couldn't set ip up because Chrome throws a pop-up for authentication. Problem is that selenium can't switch to that window and so, can't type. The only solution that worked for us was using pyautogui which is a bad solution for us because we want to use the headless function.

                Here are all the methods we tried:

                driver.switch_to_window()
                

                driver.switch_to_active_element()
                

                driver.switch_to_alert()
                

                ActionChains(driver).send_keys("test").perform()
                

                driver.switch_to_alert()
                

                options = webdriver.ChromeOptions()
                options.add_argument('--proxy-server=http://user:pass@3.223.68.195:31112')
                

                driver.get("https://user:pass@google.com")
                

                proxy = {'address': '3.209.253.119:31112',
                         'username': 'user',
                         'password': 'pass'}
                
                
                capabilities = dict(DesiredCapabilities.CHROME)
                capabilities['proxy'] = {'proxyType': 'MANUAL',
                                         'httpProxy': proxy['address'],
                                         'ftpProxy': proxy['address'],
                                         'sslProxy': proxy['address'],
                                         'noProxy': '',
                                         'class': "org.openqa.selenium.Proxy",
                                         'autodetect': False}
                
                capabilities['proxy']['socksUsername'] = proxy['username']
                capabilities['proxy']['socksPassword'] = proxy['password']
                
                driver = webdriver.Chrome(executable_path="chromedriver.exe", desired_capabilities=capabilities)
                driver.get("http://google.com")
                

                Any help would be really appreciated :)

                解決方案

                If you need to use a proxy with no authentication (no username or password) with python and Selenium library with chromedriver you usually use the following code:

                chrome_options = webdriver.ChromeOptions()
                chrome_options.add_argument('--proxy-server=%s' % hostname + ":" + port)
                driver = webdriver.Chrome(chrome_options=chrome_options)
                

                It works fine unless proxy requires authentication. if the proxy requires you to log in with a username and password it will not work. In this case, you have to use more tricky solution that is explained below.

                To set up proxy authentication we will generate a file and upload it to chromedriver dynamically using the following code below. This effectively create a chrome extension. This code configures selenium with chromedriver to use HTTP proxy that requires authentication with user/password pair.

                import os
                import zipfile
                
                from selenium import webdriver
                
                
                def create_chromedriver(PROXY_HOST, PROXY_PORT, PROXY_USER, PROXY_PASS, USER_AGENT):
                    manifest_json = """
                    {
                    "version": "1.0.0",
                    "manifest_version": 2,
                    "name": "Chrome Proxy",
                    "permissions": [
                        "proxy",
                        "tabs",
                        "unlimitedStorage",
                        "storage",
                        "<all_urls>",
                        "webRequest",
                        "webRequestBlocking"
                    ],
                    "background": {
                        "scripts": ["background.js"]
                    },
                    "minimum_chrome_version":"22.0.0"
                    }
                    """
                
                    background_js = """
                    var config = {
                        mode: "fixed_servers",
                        rules: {
                        singleProxy: {
                            scheme: "http",
                            host: "%s",
                            port: parseInt(%s)
                        },
                        bypassList: ["localhost"]
                        }
                    };
                
                    chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
                
                    function callbackFn(details) {
                        return {
                            authCredentials: {
                            username: "%s",
                            password: "%s"
                            }
                        };
                    }
                
                    chrome.webRequest.onAuthRequired.addListener(
                            callbackFn,
                            {urls: ["<all_urls>"]},
                            ['blocking']
                    );
                    """ % (PROXY_HOST, PROXY_PORT, PROXY_USER, PROXY_PASS)
                
                
                    def get_chromedriver(use_proxy=True, user_agent=USER_AGENT):
                        path = os.path.dirname(os.path.abspath(__file__))
                        chrome_options = webdriver.ChromeOptions()
                        if use_proxy:
                            pluginfile = 'proxy_auth_plugin.zip'
                            with zipfile.ZipFile(pluginfile, 'w') as zp:
                                zp.writestr("manifest.json", manifest_json)
                                zp.writestr("background.js", background_js)
                            chrome_options.add_extension(pluginfile)
                        if user_agent:
                            chrome_options.add_argument('--user-agent=%s' % USER_AGENT)
                        driver = webdriver.Chrome(
                            os.path.join(path, 'chromedriver'),
                            chrome_options=chrome_options)
                        return driver
                
                    driver = get_chromedriver(use_proxy=True)
                    # driver.get('https://www.google.com/search?q=my+ip+address')
                    driver.get('https://httpbin.org/ip')
                
                
                user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
                create_chromedriver('192.168.3.2', 8080, 'user', 'pass', user_agent)
                

                Function get_chromedriver returns configured selenium web driver that you can use in your application. This code is tested and works just fine.

                To implement this into your own code just call the function create_chromedriver with args of host, port, user, pass and user-agent. If you do not want to use proxy or user-agent just edit get_chromedriver accordingly so the args are false.

                這篇關于通過 Selenium chromedriver 進行 Python 代理身份驗證的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機器人?)
                Discord bot isn#39;t responding to commands(Discord 機器人沒有響應命令)
                Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關于我嗎?Discord 機器人的功能?(不和諧.py))
                message.channel.id Discord PY(message.channel.id Discord PY)
                How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機器人?)
                discord.py - Automaticaly Change an Role Color(discord.py - 自動更改角色顏色)

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

                    • <bdo id='Eyt5s'></bdo><ul id='Eyt5s'></ul>
                    • <legend id='Eyt5s'><style id='Eyt5s'><dir id='Eyt5s'><q id='Eyt5s'></q></dir></style></legend>

                      <tfoot id='Eyt5s'></tfoot>

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

                        1. 主站蜘蛛池模板: 视频一区二区在线观看 | 成在线人视频免费视频 | 欧美精品tv | 成人一区二区三区视频 | 国产精品欧美一区二区三区不卡 | 久草.com | 精品一区电影 | 日韩成人在线免费观看 | 欧美一区二区三区在线播放 | 罗宾被扒开腿做同人网站 | 91在线精品播放 | 久久精品国产清自在天天线 | 一级毛片在线播放 | 日韩成人在线播放 | 国产精品毛片一区二区三区 | 91av在线视频观看 | 久久99网 | 日本高清视频在线播放 | 精品久久久久久一区二区 | 九一在线观看 | 国产主播第一页 | 免费黄色录像片 | 欧美一区二区三区的 | 中文字幕在线观看视频一区 | 在线播放一区二区三区 | 亚洲天天干 | 青青草这里只有精品 | 国产激情一区二区三区 | 国产激情在线 | 欧美成人不卡 | 免费在线观看一区二区 | 日韩av成人| 波多野结衣中文字幕一区二区三区 | 精品免费在线 | 国产真实精品久久二三区 | 日韩欧美在线免费 | 国产精品久久久久久久免费观看 | 日韩视频免费在线 | 亚洲精品一区二区网址 | 日本三级在线视频 | 久久精品久久久久久 |