-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
34 lines (26 loc) · 1.01 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import asyncio
import logging
import aiojobs
from proxy_spider import *
from models import bulk_upsert_proxy
from logs import logger
from ipcheck import main as ip_check
async def wrap_task(loop, spider_coro):
proxy_items = await spider_coro(loop)
upsert_result = await bulk_upsert_proxy(proxy_items)
logger.info("成功将爬取的proxy信息上传数据库: {}".format(upsert_result))
async def main(loop):
scheduler = await aiojobs.create_scheduler()
for spider_coro in (crawl_kuaidaili, crawl_xicidaili, crawl_data5u,
crawl_ip3366, crawl_66ip, crawl_usproxy,
crawl_proxydb, crawl_coolproxy, crawl_proxylist):
task = wrap_task(loop, spider_coro)
await scheduler.spawn(task)
await asyncio.sleep(60)
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))
loop.run_until_complete(ip_check())