import requests
import random
import requests.adapters
import threading
import time
targetUrlList = [
"https://httpbin.org/ip",
"https://httpbin.org/headers",
"https://httpbin.org/user-agent",
]
proxyHost = "t.16yun.cn"
proxyPort = "31111"
proxyUser = "username"
proxyPass = "password"
proxyMeta = f"http://{proxyUser}:{proxyPass}@{proxyHost}:{proxyPort}"
proxies = {
"http": proxyMeta,
"https": proxyMeta,
}
last_request_time = 0
lock = threading.Lock()
def visit_url(url, i):
global last_request_time
with requests.session() as s:
with lock:
current_time = time.time()
delta_time = current_time - last_request_time
if delta_time < 0.2:
time.sleep(0.2 - delta_time)
last_request_time = time.time()
r = s.get(url, proxies=proxies)
print(f"第{i+1}个网址,结果如下:")
print(r.text)
threads = []
for i, url in enumerate(targetUrlList):
t = threading.Thread(target=visit_url, args=(url, i))
threads.append(t)
t.start()
for t in threads:
t.join()