-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
67 lines (48 loc) · 1.47 KB
/
main.py
File metadata and controls
67 lines (48 loc) · 1.47 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
# -*- coding: utf8 -*-
import os
import sys
import json
from selenium import webdriver
from crawler.jiandan import JiandanCrawler
from crawler.mzitu import MzituCrawler
from crawler.miaotuba import MiaotubaCrawler
from crawler.pangci import PangciCrawler
cwd_path = os.getcwd()
crawlers = {
'jiandan': JiandanCrawler,
'mzitu': MzituCrawler,
'miaotuba': MiaotubaCrawler,
'pangci': PangciCrawler
}
def get_config():
config_path = os.path.join(cwd_path, 'hia.config.json')
if not os.path.exists(config_path):
return {
'webDriver': {
'name': 'Chrome',
'path': 'C:/Program Files (x86)/Google/Chrome/Application/chromedriver.exe'
}
}
with open(config_path) as i:
config = json.load(i)
print('\n> load configuration from ' + config_path + '\n')
return config
def main():
argv = sys.argv
if len(argv) < 2:
print('\n*** Lack of crawler name ***\n\nUsage: python main.py <crawler>\n')
exit(1)
crawler = argv[1]
if crawlers.get(crawler) is None:
print('\n*** Unknown crawler ***\n')
exit(1)
config = get_config()
print('> open browser\n')
browser = webdriver.Chrome(config['webDriver']['path'])
dir_path = os.path.join(os.getcwd(), 'imgs', crawler)
print('> start crawl\n')
crawlers.get(crawler)(browser, dir_path)
print('> finish crawl')
if __name__ == '__main__':
main()