-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsettings.py.example
58 lines (47 loc) · 2.3 KB
/
settings.py.example
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
'''
Created on May 12, 2017
@author: yingziwu
'''
# Settings
## v2ex account #建议使用小号
account='v2ex_account' #v2ex帐号
password='v2ex_password' #v2ex密码
## User-Agent setting
### WEB_User_Agents:访问v2ex网页版时使用的UA池。请自行添加
WEB_User_Agents=['Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2869.0 Safari/537.36']
### API_User_Agents:调用v2ex API时使用的UA池。请自行添加
API_User_Agents=['Mozilla/5.0 (Linux; Android 6.0; Nexus 5X Build/MDB08L) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.124 Mobile Safari/537.36']
## proxy setting
proxy_enable=False #是否对一般请求使用代理,默认值为不使用。
### proxies_list:代理池,具体说明详见:http://docs.python-requests.org/en/master/user/advanced/#proxies
proxies_list=[{"http":"socks5://localhost:1080","https":"socks5://localhost:1080"},
{"http":"http://localhost:8090","https":"http://localhost:8090"},]
i_proxy_enable=False #是否对重要请求使用代理,默认值为不使用。(run.py、log_in.py、rss_spider.py为重要请求)
i_proxies_list=[{"http":"socks5://127.0.0.1:1080","https":"socks5://127.0.0.1:1080"}]
## database setting
database_path="/home/arch/python/v2ex_delete/database.db" #sqlite数据库路径
## log
import logging
import os
log_level=logging.INFO #log等级
log_dir='log' #log路径
log_path=os.path.join(log_dir,'all.log')
logging.basicConfig(level=log_level,
filename=log_path,filemode='a',
format='%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s')
## mode (Mode1 or Mode2)
mode='Mode1' #抓取模式
# Program
import random
WEB_headers={'Accept':"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
'Accept-Encoding':"gzip, deflate",
'Accept-Language':"zh-CN,zh;q=0.8",
'User-Agent':random.choice(WEB_User_Agents)}
API_headers={'Accept':"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
'Accept-Encoding':"gzip, deflate",
'Accept-Language':"zh-CN,zh;q=0.8",
'User-Agent':random.choice(API_User_Agents)}
def proxies():
return random.choice(proxies_list)
def i_proxies():
return random.choice(i_proxies_list)