def append_user_agent ( self , user_agent ) : old_ua = self . session . headers . get ( 'User-Agent' , '' ) ua = old_ua + ' ' + user_agent self . session . headers [ 'User-Agent' ] = ua . strip ( )
how to change user agent in python
Append text to the User - Agent header for the request .
def append_user_agent(self, user_agent):
        """Append text to the User-Agent header for the request.

        Use this method to update the User-Agent header by appending the
        given string to the session's User-Agent header separated by a space.

        :param user_agent: A string to append to the User-Agent header
        :type user_agent: str
        """
        old_ua = self.session.headers.get('User-Agent', '')
        ua = old_ua + ' ' + user_agent
        self.session.headers['User-Agent'] = ua.strip()