可扩展的Cookies池,用无头浏览器登录并生成cookie供给爬虫使用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.7 KiB

7 years ago
import time
from multiprocessing import Process
7 years ago
7 years ago
from cookiespool.api import app
7 years ago
from cookiespool.config import *
7 years ago
from cookiespool.generator import *
from cookiespool.tester import *
7 years ago
7 years ago
7 years ago
class Scheduler(object):
@staticmethod
def valid_cookie(cycle=CYCLE):
while True:
7 years ago
print('Cookies检测进程开始运行')
7 years ago
try:
7 years ago
for website, cls in TESTER_MAP.items():
tester = eval(cls + '(website="' + website + '")')
7 years ago
tester.run()
7 years ago
print('Cookies检测完成')
7 years ago
del tester
time.sleep(cycle)
except Exception as e:
print(e.args)
7 years ago
7 years ago
@staticmethod
def generate_cookie(cycle=CYCLE):
while True:
7 years ago
print('Cookies生成进程开始运行')
7 years ago
try:
7 years ago
for website, cls in GENERATOR_MAP.items():
generator = eval(cls + '(website="' + website + '")')
7 years ago
generator.run()
7 years ago
print('Cookies生成完成')
7 years ago
generator.close()
time.sleep(cycle)
except Exception as e:
print(e.args)
7 years ago
7 years ago
@staticmethod
def api():
7 years ago
print('API接口开始运行')
7 years ago
app.run(host=API_HOST, port=API_PORT)
7 years ago
7 years ago
def run(self):
7 years ago
if API_PROCESS:
api_process = Process(target=Scheduler.api)
api_process.start()
7 years ago
if GENERATOR_PROCESS:
generate_process = Process(target=Scheduler.generate_cookie)
generate_process.start()
7 years ago
7 years ago
if VALID_PROCESS:
valid_process = Process(target=Scheduler.valid_cookie)
valid_process.start()