How to change the value of a class property through a class method?

as in the following code, I created a middleware and launched a browser in the _ _ init__ method. I want to update the agent of driver = webdriver.PhantomJS (service_args=service_args) through the process_request method, and how to change the code.

class Phantomjs_Middlewares(object):
    def __init__(self,service_args=[]):
        redis_client_pool = redis.ConnectionPool(host="1.1.1.1", port=6378, password="123456")
        self.aaa_redis = redis.Redis(connection_pool=redis_client_pool)
        self.driver =  webdriver.PhantomJS(service_args=service_args)
        
    def get_proxy(self):
        return self.aaa_redis.randomkey()

    def __del__(self):
        self.driver.quit()
        
    def process_request(self,request,spider):
        service_args = [
            "--proxy=%s"%self.get_proxy(),
            "--proxy-type=http",
            "--load-images=no",
            "--disk-cache=yes",
            "--ignore-ssl-errors=true"
        ]
        -sharp__init__
        self.driver(service_args=service_args)-sharp
        driver.get(url=request.url)
        return HtmlResponse(url=driver.current_url, body=driver.page_source, encoding="utf-8", request=request)
        

Menu