__init__.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from concurrent.futures import ThreadPoolExecutor, ALL_COMPLETED, wait
  2. from crawler.spiders import (
  3. SXSpider,
  4. GDSpider,
  5. BJSpider,
  6. TJSpider,
  7. HuSpider,
  8. SHSpider,
  9. HBSpider,
  10. SHNDSpider
  11. )
  12. from utils.log import logger
  13. def bj_spider(max_workers):
  14. return BJSpider().run(True, max_workers)
  15. def tj_spider(max_workers):
  16. return TJSpider().run(True, max_workers)
  17. def hu_spider(max_workers):
  18. return HuSpider().run(True, max_workers)
  19. def gd_spider(max_workers):
  20. return GDSpider().run(True, max_workers)
  21. def sx_spider(max_workers):
  22. return SXSpider().run(True, max_workers)
  23. def sh_spider(max_workers):
  24. return SHSpider().run(True, max_workers)
  25. def hb_spider(max_workers):
  26. return HBSpider().run(True, max_workers)
  27. def sh_nd_spider(max_workers):
  28. return SHNDSpider().run(True, max_workers)
  29. def activate_spider(max_workers: int = 1):
  30. futures = []
  31. with ThreadPoolExecutor(max_workers=max_workers) as Executor:
  32. # futures.append(Executor.submit(bj_spider, 2))
  33. # futures.append(Executor.submit(tj_spider, 2))
  34. # futures.append(Executor.submit(hb_spider, 2))
  35. futures.append(Executor.submit(hu_spider, 2))
  36. # futures.append(Executor.submit(gd_spider, 2))
  37. # futures.append(Executor.submit(sx_spider, 2))
  38. # futures.append(Executor.submit(sh_spider, 2))
  39. # futures.append(Executor.submit(sh_nd_spider, 2))
  40. wait(futures, return_when=ALL_COMPLETED)
  41. logger.info('[采集]采集完成')