请求通过https keep-alive直到一个好的响应(perl或python2.7)

时间:2015-09-14 06:54:48

标签: perl python-2.7 http https keep-alive

我希望继续通过https Keep-Alive连接发送一些HTTP请求,直到我得到一个好的响应(例如,匹配某个字符串/正则表达式的响应)。

perlpython2.7中执行此操作的最佳方式是什么? (我是C程序员,不太了解Perl或Python。)

1 个答案:

答案 0 :(得分:0)

import requests

def deal_with_specal_case(res -> request.response):
    print("oops server error")


# main
url = 'https://www.google.com/?search=foobar'
res = requests.get(url)

while True:
    if res.response_code == '200' and any(mystring in x for x in res.text.splitlines()): break
    else:
        res = requests.get(url)
        if res.response_code > 499:
            deal_with_special_case(res)
            break