import smtplib,schedule
# 通过CrawlerProcess同时运行几个spider
from scrapy.crawler import CrawlerProcess
from spiders.liepin_spider import LiepinSpiderSpider as lie_1
from spiders.liepin_spider_2 import LiepinSpiderSpider as lie_2
from spiders.liepin_spider_3 import LiepinSpiderSpider as lie_3
# 导入获取项目配置的模块
from scrapy.utils.project import get_project_settings
def start_spider():
try:
#一定要先加载配置文件
process = CrawlerProcess(get_project_settings())
process.crawl(lie_1)
process.crawl(lie_2)
process.crawl(lie_3)
process.start()
now_time = time.strftime('%Y-%m-%d', time.localtime(time.time()))
print('---{}---执行完成'.format(now_time))
except Exception as e:
print('--出现错误--', e)
#email_spider('liepin', e) #发送邮件的方法,可以自己写
def main():
print('开始检测,等待时间到达,开始执行')
schedule.every().day.at("13:04").do(start_spider)
schedule.every().day.at("17:00").do(start_spider)
while True:
schedule.run_pending()
time.sleep(10)
if __name__ == '__main__':
main()
schedule和CrawlerProcess定时执行多个爬虫
最新推荐文章于 2024-04-02 15:05:07 发布