Kevser 4 months ago
Back-end development
Create mobile and desktop request  on Python 

Return => response , decoded response body

mobile_user_agent = ''
desktop_user_agent = ''
def create_request(url, is_mobile):
    try:
        if is_mobile:
            res = requests.get(url, headers={'user-agent': mobile_user_agent})

        res = requests.get(url, headers={'user-agent': desktop_user_agent})

        if res.status_code is not 200:
            return res, ''

        res_page_source = res.content.decode('utf-8')
        return res, res_page_source
    except Exception as ex:
        print(ex)
        return "", ""