forked from awolfly9/IPProxyTool
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_spider.py
35 lines (28 loc) · 951 Bytes
/
run_spider.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
35
# -*- coding: utf-8 -*-
import os
import logging
import sys
from scrapy.crawler import CrawlerProcess
from scrapy.utils.log import configure_logging
from scrapy.utils.project import get_project_settings
def runspider(name):
configure_logging(install_root_handler=False)
logging.basicConfig(
filename='log/%s.log' % name,
format='%(levelname)s %(asctime)s: %(message)s',
level=logging.DEBUG
)
process = CrawlerProcess(get_project_settings())
try:
logging.info('runspider start spider:%s' % name)
process.crawl(name)
process.start()
except Exception as e:
logging.exception('runspider spider:%s exception:%s' % (name, e))
logging.debug('finish this spider:%s\n\n' % name)
if __name__ == '__main__':
try:
name = sys.argv[1] or 'base'
runspider(name)
except Exception as e:
logging.exception('run_spider main exception msg:%s' % e)