如何在python中非常快速地发送大量的帖子请求?

时间:2017-06-16 11:37:58

标签: python post request

这是我用python语言发送大量POST请求的代码。它工作正常。但这太慢了。我想是因为它一个接一个地发送POST请求。 我要问: 1.我怎样才能以更快的速度发送POST请求的方式制作这段代码? 2.如何在不等待响应的情况下发送POST请求?

import sys
import json
import requests
import time
url = "http://club.raakdarou.com/users/main/GettingGift"
number=2237499999938616
headers={'Host': 'club.raakdarou.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0',
'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested-With': 'XMLHttpRequest',
'Referer': 'http://club.raakdarou.com/users/main',
'Content-Length': '53',
'Cookie': 'ASP.NET_SessionId=4sirmg5n05fkszmvbasr4vnt; __RequestVerificationToken=AsWNgNzLVjU8kCNvWvTjn_tJiBlEKE5NH_xO-o7eGkq3h3av7I1e0_qu6NO80SNKfiV-c5Ajm6nlrDE7pFcKFkdr6ZHVX9zXAWYZt79c_pw1',
'Connection': 'keep-alive'}
def sendRequest(number):
    try:
        while(number>=2237400000000000):
            data = {'gift': number , 'X-Requested-With' : 'XMLHttpRequest'}
            r = requests.post(url, data=json.dumps(data), headers=headers)
            print(number)
            number=number-1

    except:
        print ("Unexpected error:", sys.exc_info()[0])
        sendRequest(number+1)

0 个答案:

没有答案