forked from itstyren/CNKI-download
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetConfig.py
78 lines (63 loc) · 1.91 KB
/
GetConfig.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
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
68
69
70
71
72
73
74
75
76
77
78
"""
-------------------------------------------------
File Name: GetConfig.py
Description : 获取配置信息
Author : Cyrus_Ren
date: 2018/12/10
-------------------------------------------------
Change Activity:
-------------------------------------------------
"""
__author__ = 'Cyrus_Ren'
import os
import configparser
class LazyProperty(object):
"""
LazyProperty
explain: http://www.spiderpy.cn/blog/5/
"""
def __init__(self, func):
self.func = func
def __get__(self, instance, owner):
if instance is None:
return self
else:
value = self.func(instance)
setattr(instance, self.func.__name__, value)
return value
class GetConfig(object):
"""
to get config from config.ini
"""
def __init__(self):
self.conf=configparser.ConfigParser()
self.conf.read('./Config.ini', encoding='UTF-8')
@LazyProperty
def crawl_isdownload(self):
return self.conf.get('crawl','isDownloadFile')
@LazyProperty
def crawl_iscrackcode(self):
return self.conf.get('crawl', 'isCrackCode')
@LazyProperty
def crawl_headers(self):
headers = {
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36',
'Host':
'kns.cnki.net',
'Connection':
'keep-alive',
'Cache-Control':
'max-age=0',
}
return headers
@LazyProperty
def crawl_isdetail(self):
return self.conf.get('crawl', 'isDetailPage')
@LazyProperty
def crawl_stepWaitTime(self):
return int(self.conf.get('crawl', 'stepWaitTime'))
@LazyProperty
def crawl_isDownLoadLink(self):
return int(self.conf.get('crawl', 'isDownLoadLink'))
config=GetConfig()