-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathstart.py
39 lines (32 loc) · 1.12 KB
/
start.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
37
38
39
import scrapy
import os
import sys
from twisted.internet import reactor
from scrapy.crawler import CrawlerRunner
from scrapy.utils.project import get_project_settings
from scrapy.utils.log import configure_logging
import importlib
def remove(target_list, remove_list):
for i in remove_list:
if i in target_list:
target_list.remove(i)
def filter(classes):
for item in classes:
if item.endswith('Spider'):
return item
def start():
sys.path.append('./proxy_pool/spiders/')
files = os.listdir('./proxy_pool/spiders/')
remove(files, ['__init__.py', '__pycache__'])
runner = CrawlerRunner(get_project_settings())
configure_logging()
for file in files:
module = importlib.import_module(file.split('.')[0])
classes = dir(module)
remove(classes, ['__builtins__', '__cached__', '__doc__', '__file__',
'ProxyPoolItem', '__loader__', '__name__', '__package__', '__spec__', 'scrapy'])
runner.crawl(getattr(module, filter(classes)))
d = runner.join()
d.addBoth(lambda _: reactor.stop())
reactor.run()
start()