|
@@ -9,6 +9,8 @@ import redis
|
|
|
import requests
|
|
import requests
|
|
|
import schedule
|
|
import schedule
|
|
|
|
|
|
|
|
|
|
+from tools import redis_client
|
|
|
|
|
+
|
|
|
|
|
|
|
|
# 随机生成token
|
|
# 随机生成token
|
|
|
def get_token():
|
|
def get_token():
|
|
@@ -161,16 +163,14 @@ def save_proxy_ip(page, page_size):
|
|
|
proxy = f'{username}:{password}@{proxy_address_ip}:{port}'
|
|
proxy = f'{username}:{password}@{proxy_address_ip}:{port}'
|
|
|
|
|
|
|
|
# 连接Redis并存储代理IP
|
|
# 连接Redis并存储代理IP
|
|
|
- r = redis.Redis(host='localhost', port=6379, db=0)
|
|
|
|
|
- r.set(f'proxy_{str(i)}', proxy)
|
|
|
|
|
|
|
+ redis_client.set(f'proxy_{str(i)}', proxy)
|
|
|
i = i + 1
|
|
i = i + 1
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_random_proxy_at_redis(total):
|
|
def get_random_proxy_at_redis(total):
|
|
|
random_index = random.randint(0, total - 1)
|
|
random_index = random.randint(0, total - 1)
|
|
|
# 连接Redis并获取代理IP
|
|
# 连接Redis并获取代理IP
|
|
|
- r = redis.Redis(host='localhost', port=6379, db=0)
|
|
|
|
|
- single_proxy = r.get(f'proxy_{str(random_index)}')
|
|
|
|
|
|
|
+ single_proxy = redis_client.get(f'proxy_{str(random_index)}')
|
|
|
|
|
|
|
|
return single_proxy
|
|
return single_proxy
|
|
|
|
|
|
|
@@ -227,4 +227,4 @@ if __name__ == "__main__":
|
|
|
# file_writer = FileWriter('output.txt')
|
|
# file_writer = FileWriter('output.txt')
|
|
|
# file_writer.write_to_file('Hello, World!')
|
|
# file_writer.write_to_file('Hello, World!')
|
|
|
# 代理池存储到redis
|
|
# 代理池存储到redis
|
|
|
- save_proxy_ip(5, 30)
|
|
|
|
|
|
|
+ save_proxy_ip(1, 200)
|