forked from awolfly9/IPProxyTool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runscrapy.py
36 lines (28 loc) · 938 Bytes
/
runscrapy.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
36
#-*- 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 runscrapy(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('runscrapy start spider:%s' % name)
process.crawl(name)
process.start()
except Exception, e:
logging.error('runscrapy spider:%s exception:%s' % (name, e))
pass
logging.info('finish this spider:%s\n\n' % name)
if __name__ == '__main__':
name = sys.argv[1] or 'base'
print('name:%s' % name)
print ('project dir:%s' % os.getcwd())
runscrapy(name)