【发布时间】:2019-10-10 18:12:06
【问题描述】:
我正在使用 Python 请求来检查代理是否正常工作。我将它们加载到 IP:PORT 格式的 .txt 文件中。然后,我使用 Threading 模块设置了线程,并且它可以工作。一个问题 - 它在每个线程上运行在相同的 IP:PORT 上。一旦所有线程都完成了第一行,它就会移动到第二行。我想让每个线程尝试不同的 IP:PORT,直到所有线程都被检查。
我四处寻找,但找不到我要找的东西。我实际上已经坚持了几个星期。
import requests
import threading
def ip():
with open('ip_found.txt', 'r') as i:
iport = [x.strip().split(':', 1) for x in i]
postIt = { 'ip' : ip, 'port' : port }
r1 = requests.post(URL"",data=postIt)
for _ in range(2):
for ip, port in iport:
t1 = threading.thread(target=ip)
t1.start()
t2 = threading.thread(target=ip)
t2.start()
【问题讨论】:
-
您需要发布minimal reproducible example 的代码——您当前的问题不是一个。
标签: python multithreading python-requests