示例#1
0
def do_request(url):
    retry = 5
    headers = HEADERS_VIDEO
    html = None
    while retry > 0:
        try:
            resp = ssn.get(url=url, headers=headers)
            if resp.status_code < 300:
                html = resp.content.decode('utf-8')
                break
            time.sleep(5)
        except Exception as e:
            print('请求出错', e)
            time.sleep(10)
        retry -= 1
    return html
示例#2
0
def do_simple_request(referer, params):
    retry = 5
    headers = HEADERS_VIDEO
    headers.update({'referer': referer})
    html = None
    while retry > 0:
        try:
            resp = ssn.get(url=URL_1, headers=headers, params=params)
            print(resp.status_code)
            if resp.status_code < 300:
                html = resp.content.decode('utf-8')
                break
            time.sleep(1)
        except Exception as e:
            print('请求出错', e)
            time.sleep(10)
        retry -= 1
    return html