Abu Cloud in python switches over ip in selenium

from selenium import webdriver
import string
import zipfile
import os
-sharp 
proxyHost = "http-dyn.abuyun.com"
proxyPort = "9020"

-sharp 
proxyUser = "HZOM2R924752778D"
proxyPass = "C78569FFC6E8C219"


def create_proxy_auth_extension(proxy_host, proxy_port,
                                proxy_username, proxy_password,
                                scheme="http", plugin_path=None):
    if plugin_path is None:
        plugin_path = os.getcwd()+r"/{}_{}@http-dyn.abuyun.com_9020.zip".format(proxy_username, proxy_password)

    manifest_json = """
       {
           "version": "1.0.0",
           "manifest_version": 2,
           "name": "Abuyun Proxy",
           "permissions": [
               "proxy",
               "tabs",
               "unlimitedStorage",
               "storage",
               "<all_urls>",
               "webRequest",
               "webRequestBlocking"
           ],
           "background": {
               "scripts": ["background.js"]
           },
           "minimum_chrome_version":"22.0.0"
       }
       """
    print("sadadaasda")

    background_js = string.Template(
        """
        var config = {
            mode: "fixed_servers",
            rules: {
                singleProxy: {
                    scheme: "${scheme}",
                    host: "${host}",
                    port: parseInt(${port})
                },
                bypassList: ["foobar.com"]
            }
          };

        chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});

        function callbackFn(details) {
            return {
                authCredentials: {
                    username: "${username}",
                    password: "${password}"
                }
            };
        }

        chrome.webRequest.onAuthRequired.addListener(
            callbackFn,
            {urls: ["<all_urls>"]},
            ["blocking"]
        );
        """
    ).substitute(
        host=proxy_host,
        port=proxy_port,
        username=proxy_username,
        password=proxy_password,
        scheme=scheme,
    )

    with zipfile.ZipFile(plugin_path, "w") as zp:
        zp.writestr("manifest.json", manifest_json)
        zp.writestr("background.js", background_js)
    print("bbbbbb")

    return plugin_path


proxy_auth_plugin_path = create_proxy_auth_extension(
    proxy_host=proxyHost,
    proxy_port=proxyPort,
    proxy_username=proxyUser,
    proxy_password=proxyPass)
print("cccccccc")

option = webdriver.ChromeOptions()
option.add_argument("-headless")

option.add_argument("--start-maximized")
option.add_extension(proxy_auth_plugin_path)
print("ddddddd")
driver = webdriver.Chrome(options=option)
print("eeeeeee")

the header test of the reference address on Abu Yun"s official website is OK, but the headless one seems to be unsuccessful
https://www.abuyun.com/http-p.
error report as follows

File "test.py", line 102, in <module>
        driver = webdriver.Chrome(options=option)
      File "/usr/lib/python3.4/site-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
        desired_capabilities=desired_capabilities)
      File "/usr/lib/python3.4/site-packages/selenium/webdriver/remote/webdriver.py", line 156, in __init__
        self.start_session(capabilities, browser_profile)
      File "/usr/lib/python3.4/site-packages/selenium/webdriver/remote/webdriver.py", line 245, in start_session
        response = self.execute(Command.NEW_SESSION, parameters)
      File "/usr/lib/python3.4/site-packages/selenium/webdriver/remote/webdriver.py", line 314, in execute
        self.error_handler.check_response(response)
      File "/usr/lib/python3.4/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
        raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.WebDriverException: Message: unknown error: failed to wait for extension background page to load: chrome-extension://bbdjbmipiolfikadhebfcbojekkhbhfc/_generated_background_page.html
    from unknown error: page could not be found: chrome-extension://bbdjbmipiolfikadhebfcbojekkhbhfc/_generated_background_page.html
      (Driver info: chromedriver=2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),platform=Linux 3.10.0-514.26.2.el7.x86_64 x86_64)
        driver.get("http://test.abuyun.com")







Mar.19,2021

currently, chrome officially does not support mounting plug-ins in headless mode. For headless mode, refer to the following links:
1, https://blog.apify.com/how-to.
2, ide-credentials-auth-for-proxy" rel=" nofollow noreferrer "> https://stackoverflow.com/que.

Menu