rqsession 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rqsession/__init__.py +4 -0
- rqsession/config.ini +5 -0
- rqsession/config_util.py +21 -0
- rqsession/logger.py +10 -0
- rqsession/request_session.py +625 -0
- rqsession/static/language.txt +50 -0
- rqsession/static/proxies.txt +0 -0
- rqsession/static/useragents.txt +125 -0
- rqsession-0.1.0.dist-info/LICENSE +201 -0
- rqsession-0.1.0.dist-info/METADATA +198 -0
- rqsession-0.1.0.dist-info/RECORD +12 -0
- rqsession-0.1.0.dist-info/WHEEL +4 -0
rqsession/__init__.py
ADDED
rqsession/config.ini
ADDED
rqsession/config_util.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import configparser
|
|
3
|
+
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def base_dir_path() -> Path:
|
|
8
|
+
# 判断是否在打包环境中运行
|
|
9
|
+
if getattr(sys, 'frozen', False):
|
|
10
|
+
# 如果是打包环境(EXE),使用sys.executable的位置
|
|
11
|
+
application_path = Path(sys.executable).parent.absolute()
|
|
12
|
+
else:
|
|
13
|
+
# 如果是开发环境,使用__file__
|
|
14
|
+
application_path = Path(__file__).parent.parent.absolute()
|
|
15
|
+
return application_path
|
|
16
|
+
|
|
17
|
+
def get_config_ini() -> configparser.ConfigParser:
|
|
18
|
+
config_path = base_dir_path().joinpath("rqsession", "config.ini")
|
|
19
|
+
c = configparser.ConfigParser()
|
|
20
|
+
c.read(config_path)
|
|
21
|
+
return c
|
rqsession/logger.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
logger = logging.getLogger('default')
|
|
5
|
+
console_handler = logging.StreamHandler(sys.stdout)
|
|
6
|
+
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(funcName)s - %(message)s')
|
|
7
|
+
console_handler.setFormatter(formatter)
|
|
8
|
+
logger.addHandler(console_handler)
|
|
9
|
+
logger.setLevel(logging.INFO)
|
|
10
|
+
|
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import random
|
|
3
|
+
import time
|
|
4
|
+
import json
|
|
5
|
+
import uuid
|
|
6
|
+
import os
|
|
7
|
+
|
|
8
|
+
from urllib.parse import urlparse
|
|
9
|
+
from http.cookiejar import Cookie
|
|
10
|
+
|
|
11
|
+
from requests import HTTPError, Timeout
|
|
12
|
+
from requests.exceptions import SSLError, ProxyError
|
|
13
|
+
|
|
14
|
+
from .logger import logger
|
|
15
|
+
from .config_util import get_config_ini
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
base_config = get_config_ini()
|
|
19
|
+
# 默认配置
|
|
20
|
+
DEFAULT_CONFIG = {
|
|
21
|
+
"host": base_config["RequestSession"]["host"],
|
|
22
|
+
"port": base_config["RequestSession"]["port"],
|
|
23
|
+
"enabled": base_config["RequestSession"]["use_proxy"] == "1",
|
|
24
|
+
"random_proxy": False,
|
|
25
|
+
"print_log": base_config["RequestSession"]["log"] == "1",
|
|
26
|
+
"proxy_file": "static/proxies.txt",
|
|
27
|
+
"max_history_size": 100,
|
|
28
|
+
"auto_headers": False, # 设置默认的自动配置请求头、例如:Host、Referer、Origin 是否自动设置
|
|
29
|
+
"user_agents_file": "static/useragents.txt",
|
|
30
|
+
"languages_file": "static/language.txt",
|
|
31
|
+
"work_path": "tmp/http_session"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
os.makedirs(DEFAULT_CONFIG["work_path"], exist_ok=True)
|
|
35
|
+
os.makedirs(DEFAULT_CONFIG["work_path"] + "/log", exist_ok=True)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# import logging
|
|
39
|
+
# logger = logging.getLogger(__name__)
|
|
40
|
+
# logging.basicConfig(
|
|
41
|
+
# level=logging.INFO,
|
|
42
|
+
# format='%(asctime)s - %(name)s - %(levelname)s - %(funcName)s - %(message)s',
|
|
43
|
+
# handlers=[
|
|
44
|
+
# logging.StreamHandler(), # 输出到控制台
|
|
45
|
+
# logging.FileHandler(DEFAULT_CONFIG["work_path"] + '/log/access.log') # 输出到文件
|
|
46
|
+
# ]
|
|
47
|
+
# )
|
|
48
|
+
# logger.setLevel(logging.INFO)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class RequestSession(requests.Session):
|
|
53
|
+
def __init__(self, proxy_method=None, proxy_file=None, config=None, **kwargs):
|
|
54
|
+
"""初始化请求会话
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
proxy_method: 自定义获取代理的方法
|
|
58
|
+
proxy_file: 代理文件路径
|
|
59
|
+
config: 配置字典,包含代理设置等
|
|
60
|
+
"""
|
|
61
|
+
super().__init__()
|
|
62
|
+
|
|
63
|
+
config = config or DEFAULT_CONFIG
|
|
64
|
+
|
|
65
|
+
# 基本属性设置
|
|
66
|
+
self._id = str(uuid.uuid4()).replace("-", "")
|
|
67
|
+
self.file_name = self._id
|
|
68
|
+
self.create_time = int(time.time())
|
|
69
|
+
self.modify_time = int(time.time())
|
|
70
|
+
self.work_dir = config.get("work_path", "tmp/http_session")
|
|
71
|
+
|
|
72
|
+
# 代理设置
|
|
73
|
+
default_host = config.get("host", "127.0.0.1")
|
|
74
|
+
default_port = config.get("port", "7890")
|
|
75
|
+
self.proxies_list = [f"http://{default_host}:{default_port}"]
|
|
76
|
+
self.proxy_file = proxy_file
|
|
77
|
+
self.proxy_method = proxy_method
|
|
78
|
+
self.use_proxy = bool(config.get("enabled", False))
|
|
79
|
+
self.random_proxy = bool(config.get("random_proxy", False))
|
|
80
|
+
|
|
81
|
+
# 自动处理请求头设置
|
|
82
|
+
self.auto_headers = bool(config.get("auto_headers", False))
|
|
83
|
+
|
|
84
|
+
# 日志设置
|
|
85
|
+
self.print_log = bool(config.get("print_log", True))
|
|
86
|
+
|
|
87
|
+
# 请求历史
|
|
88
|
+
self.request_history = []
|
|
89
|
+
self.max_history_size = config.get("max_history_size", 100)
|
|
90
|
+
|
|
91
|
+
# 资源文件路径
|
|
92
|
+
self.user_agents_file = config.get("user_agents_file", "static/useragents.txt")
|
|
93
|
+
self.languages_file = config.get("languages_file", "static/language.txt")
|
|
94
|
+
|
|
95
|
+
# 如果提供了代理文件,加载代理
|
|
96
|
+
if proxy_file and os.path.exists(proxy_file):
|
|
97
|
+
with open(proxy_file, 'r', encoding='utf-8') as f:
|
|
98
|
+
self.proxies_list = [line.strip() for line in f if line.strip()]
|
|
99
|
+
|
|
100
|
+
def set_proxy(self, use_proxy=True, random_proxy=True):
|
|
101
|
+
"""设置代理的使用与否和获取方式"""
|
|
102
|
+
self.use_proxy = use_proxy
|
|
103
|
+
self.random_proxy = random_proxy
|
|
104
|
+
|
|
105
|
+
def get_proxy(self):
|
|
106
|
+
"""获取代理"""
|
|
107
|
+
|
|
108
|
+
# 自己配置的获取代理的方法、返回一个: http://xxxx:xx 这样的代理地址、可携带 username 与 password
|
|
109
|
+
if self.proxy_method:
|
|
110
|
+
return self.proxy_method()
|
|
111
|
+
|
|
112
|
+
if self.proxies_list:
|
|
113
|
+
if self.random_proxy and len(self.proxies_list) > 1:
|
|
114
|
+
return random.choice(self.proxies_list)
|
|
115
|
+
else:
|
|
116
|
+
return self.proxies_list[0]
|
|
117
|
+
return None
|
|
118
|
+
|
|
119
|
+
def send(self, request, **kwargs):
|
|
120
|
+
"""重写send方法来控制是否使用代理并自动处理请求头"""
|
|
121
|
+
try:
|
|
122
|
+
# 自动设置请求头
|
|
123
|
+
if self.auto_headers:
|
|
124
|
+
parsed_url = urlparse(request.url)
|
|
125
|
+
|
|
126
|
+
# 设置Host
|
|
127
|
+
if 'Host' not in request.headers:
|
|
128
|
+
request.headers['Host'] = parsed_url.netloc
|
|
129
|
+
|
|
130
|
+
# 设置Referer (如果没有提供)
|
|
131
|
+
if 'Referer' not in request.headers and kwargs.get('auto_referer', True):
|
|
132
|
+
referer = f"{parsed_url.scheme}://{parsed_url.netloc}"
|
|
133
|
+
request.headers['Referer'] = referer
|
|
134
|
+
|
|
135
|
+
# 设置Origin (对POST请求特别有用)
|
|
136
|
+
if request.method in ['POST', 'PUT', 'DELETE', 'PATCH'] and 'Origin' not in request.headers:
|
|
137
|
+
origin = f"{parsed_url.scheme}://{parsed_url.netloc}"
|
|
138
|
+
request.headers['Origin'] = origin
|
|
139
|
+
|
|
140
|
+
# 代理处理
|
|
141
|
+
used_proxies = None
|
|
142
|
+
if self.use_proxy:
|
|
143
|
+
proxy = self.get_proxy()
|
|
144
|
+
if proxy:
|
|
145
|
+
used_proxies = {'http': proxy, 'https': proxy}
|
|
146
|
+
kwargs['proxies'] = used_proxies
|
|
147
|
+
|
|
148
|
+
# 记录请求开始时间
|
|
149
|
+
request_start_time = time.time()
|
|
150
|
+
|
|
151
|
+
# 发送请求
|
|
152
|
+
response = super().send(request, **kwargs)
|
|
153
|
+
|
|
154
|
+
# 计算请求耗时
|
|
155
|
+
request_duration = time.time() - request_start_time
|
|
156
|
+
|
|
157
|
+
# 记录请求和响应
|
|
158
|
+
self.log_request_and_response(request, response, used_proxies, request_duration)
|
|
159
|
+
|
|
160
|
+
return response
|
|
161
|
+
except ProxyError as e:
|
|
162
|
+
logger.error("代理连接失败: {}".format(e))
|
|
163
|
+
raise e
|
|
164
|
+
except (HTTPError, SSLError, ConnectionError) as e:
|
|
165
|
+
logger.error("连接错误: {}".format(e))
|
|
166
|
+
raise e
|
|
167
|
+
except Timeout as e:
|
|
168
|
+
logger.error("请求响应超时: {}".format(e))
|
|
169
|
+
raise e
|
|
170
|
+
except Exception as e:
|
|
171
|
+
logger.error("网络请求其他错误: {}".format(e))
|
|
172
|
+
raise e
|
|
173
|
+
|
|
174
|
+
def initialize_session(self, headers=None, random_init=True):
|
|
175
|
+
"""初始化session的请求特征"""
|
|
176
|
+
if headers:
|
|
177
|
+
self.headers.update(headers)
|
|
178
|
+
return
|
|
179
|
+
|
|
180
|
+
# 初始化其他
|
|
181
|
+
if random_init and headers is None:
|
|
182
|
+
# 尝试从文件读取User-Agent列表
|
|
183
|
+
user_agents = self._load_file_lines(self.user_agents_file, [
|
|
184
|
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
|
|
185
|
+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15",
|
|
186
|
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0"
|
|
187
|
+
])
|
|
188
|
+
|
|
189
|
+
# 尝试从文件读取语言列表
|
|
190
|
+
languages = self._load_file_lines(self.languages_file, [
|
|
191
|
+
"en-US,en;q=0.9",
|
|
192
|
+
"zh-CN,zh;q=0.9,en;q=0.8",
|
|
193
|
+
"en-GB,en;q=0.9"
|
|
194
|
+
])
|
|
195
|
+
|
|
196
|
+
headers = {
|
|
197
|
+
"User-Agent": random.choice(user_agents),
|
|
198
|
+
"Accept": "*/*",
|
|
199
|
+
"Accept-Language": random.choice(languages),
|
|
200
|
+
# "Accept-Encoding": "gzip, deflate, br",
|
|
201
|
+
"Accept-Encoding": "gzip, deflate",
|
|
202
|
+
"Connection": "keep-alive",
|
|
203
|
+
}
|
|
204
|
+
self.headers.update(headers)
|
|
205
|
+
else:
|
|
206
|
+
headers = {
|
|
207
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
|
|
208
|
+
"Accept": "*/*",
|
|
209
|
+
"Accept-Language": "en-GB,en;q=0.9",
|
|
210
|
+
"Accept-Encoding": "gzip, deflate",
|
|
211
|
+
"Connection": "keep-alive",
|
|
212
|
+
}
|
|
213
|
+
self.headers.update(headers)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def get_features(self):
|
|
217
|
+
"""获取当前session的所有特征"""
|
|
218
|
+
return {
|
|
219
|
+
'headers': dict(self.headers),
|
|
220
|
+
'cookies': self.get_cookies_by_domain(),
|
|
221
|
+
'proxies': getattr(self, 'proxies', None)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
def get_cookies_by_domain(self):
|
|
225
|
+
"""获取按域名分组的cookie字典
|
|
226
|
+
|
|
227
|
+
Returns:
|
|
228
|
+
dict: 格式为 {domain: {name: value, ...}, ...}
|
|
229
|
+
"""
|
|
230
|
+
domains = {}
|
|
231
|
+
|
|
232
|
+
for cookie in self.cookies:
|
|
233
|
+
domain = cookie.domain
|
|
234
|
+
if domain not in domains:
|
|
235
|
+
domains[domain] = {}
|
|
236
|
+
|
|
237
|
+
# 存储当前cookie的详细信息
|
|
238
|
+
cookie_info = {
|
|
239
|
+
'name': cookie.name,
|
|
240
|
+
'value': cookie.value,
|
|
241
|
+
'path': cookie.path,
|
|
242
|
+
'secure': cookie.secure,
|
|
243
|
+
'expires': cookie.expires,
|
|
244
|
+
'domain': cookie.domain,
|
|
245
|
+
'httponly': cookie.has_nonstandard_attr('httponly'),
|
|
246
|
+
'rest': {'HttpOnly': cookie.has_nonstandard_attr('httponly')} if cookie.has_nonstandard_attr(
|
|
247
|
+
'httponly') else {},
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
domains[domain][cookie.name] = cookie_info
|
|
251
|
+
|
|
252
|
+
return domains
|
|
253
|
+
|
|
254
|
+
def save_session(self, filepath=None, _id=None):
|
|
255
|
+
"""序列化当前session"""
|
|
256
|
+
if filepath:
|
|
257
|
+
save_session_path = filepath
|
|
258
|
+
elif self.file_name:
|
|
259
|
+
save_session_path = f"{self.work_dir}/{self.file_name}.json"
|
|
260
|
+
elif _id:
|
|
261
|
+
save_session_path = f"{self.work_dir}/{_id}.json"
|
|
262
|
+
elif self._id:
|
|
263
|
+
save_session_path = f"{self.work_dir}/{self._id}.json"
|
|
264
|
+
else:
|
|
265
|
+
save_session_path = f"{self.work_dir}/{uuid.uuid4().hex}.json"
|
|
266
|
+
|
|
267
|
+
# 确保目录存在
|
|
268
|
+
os.makedirs(os.path.dirname(save_session_path), exist_ok=True)
|
|
269
|
+
|
|
270
|
+
# 按域名组织的cookie
|
|
271
|
+
domain_cookies = self.get_cookies_by_domain()
|
|
272
|
+
|
|
273
|
+
with open(save_session_path, 'w', encoding='utf-8') as f:
|
|
274
|
+
json.dump({
|
|
275
|
+
'_id': self._id,
|
|
276
|
+
'use_proxy': self.use_proxy,
|
|
277
|
+
'work_dir': self.work_dir,
|
|
278
|
+
'random_proxy': self.random_proxy,
|
|
279
|
+
'auto_headers': self.auto_headers,
|
|
280
|
+
'features': self.get_features(),
|
|
281
|
+
'domain_cookies': domain_cookies, # 按域名组织的cookie
|
|
282
|
+
'create_time': self.create_time,
|
|
283
|
+
'modify_time': int(time.time()),
|
|
284
|
+
# 不保存请求历史,因为可能太大
|
|
285
|
+
}, f, ensure_ascii=False, indent=2)
|
|
286
|
+
|
|
287
|
+
return save_session_path
|
|
288
|
+
|
|
289
|
+
@classmethod
|
|
290
|
+
def load_session(cls, filepath):
|
|
291
|
+
"""反序列化为一个requests的session"""
|
|
292
|
+
with open(filepath, 'r', encoding='utf-8') as f:
|
|
293
|
+
data = json.load(f)
|
|
294
|
+
# print(data)
|
|
295
|
+
session = cls()
|
|
296
|
+
session._id = data.get('_id', str(uuid.uuid4()).replace("-", ""))
|
|
297
|
+
session.file_name = filepath.split("/")[-1].split("\\")[-1].replace(".json", "")
|
|
298
|
+
session.use_proxy = data.get("use_proxy", False)
|
|
299
|
+
session.random_proxy = data.get("random_proxy", False)
|
|
300
|
+
session.auto_headers = data.get("auto_headers", True)
|
|
301
|
+
session.work_dir = data.get("work_dir", ".")
|
|
302
|
+
session.create_time = data.get("create_time", int(time.time()))
|
|
303
|
+
|
|
304
|
+
if 'features' in data and 'headers' in data['features']:
|
|
305
|
+
session.headers.update(data['features']['headers'])
|
|
306
|
+
|
|
307
|
+
# 按域名加载cookie
|
|
308
|
+
if 'domain_cookies' in data:
|
|
309
|
+
domain_cookies = data['domain_cookies']
|
|
310
|
+
for domain, cookies in domain_cookies.items():
|
|
311
|
+
for name, cookie_info in cookies.items():
|
|
312
|
+
session.add_cookie_from_dict(cookie_info)
|
|
313
|
+
# 兼容旧格式
|
|
314
|
+
elif 'cookies' in data:
|
|
315
|
+
session.cookies.update(requests.utils.cookiejar_from_dict(data['cookies']))
|
|
316
|
+
|
|
317
|
+
return session
|
|
318
|
+
|
|
319
|
+
def add_cookie_from_dict(self, cookie_dict):
|
|
320
|
+
"""从字典中添加cookie到session
|
|
321
|
+
|
|
322
|
+
Args:
|
|
323
|
+
cookie_dict: 包含cookie信息的字典
|
|
324
|
+
"""
|
|
325
|
+
# 提取必要参数
|
|
326
|
+
name = cookie_dict.get('name')
|
|
327
|
+
value = cookie_dict.get('value')
|
|
328
|
+
domain = cookie_dict.get('domain')
|
|
329
|
+
|
|
330
|
+
if not (name and domain):
|
|
331
|
+
logger.warning(f"无法添加cookie: 缺少必要参数 name={name}, domain={domain}")
|
|
332
|
+
return
|
|
333
|
+
|
|
334
|
+
# 设置默认值
|
|
335
|
+
path = cookie_dict.get('path', '/')
|
|
336
|
+
expires = cookie_dict.get('expires')
|
|
337
|
+
secure = cookie_dict.get('secure', False)
|
|
338
|
+
|
|
339
|
+
# 创建Cookie对象
|
|
340
|
+
cookie = Cookie(
|
|
341
|
+
version=0,
|
|
342
|
+
name=name,
|
|
343
|
+
value=value,
|
|
344
|
+
port=None,
|
|
345
|
+
port_specified=False,
|
|
346
|
+
domain=domain,
|
|
347
|
+
domain_specified=bool(domain),
|
|
348
|
+
domain_initial_dot=domain.startswith('.') if domain else False,
|
|
349
|
+
path=path,
|
|
350
|
+
path_specified=bool(path),
|
|
351
|
+
secure=secure,
|
|
352
|
+
expires=expires,
|
|
353
|
+
discard=False,
|
|
354
|
+
comment=None,
|
|
355
|
+
comment_url=None,
|
|
356
|
+
rest={'HttpOnly': cookie_dict.get('httponly', False)},
|
|
357
|
+
rfc2109=False
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
# 添加到cookiejar
|
|
361
|
+
self.cookies.set_cookie(cookie)
|
|
362
|
+
|
|
363
|
+
def set_cookies(self, cookies):
|
|
364
|
+
"""根据cookie字典列表或字典初始化到session的cookies中"""
|
|
365
|
+
if isinstance(cookies, list):
|
|
366
|
+
for cookie_dict in cookies:
|
|
367
|
+
if isinstance(cookie_dict, dict) and 'name' in cookie_dict and 'value' in cookie_dict:
|
|
368
|
+
# 如果是完整的cookie信息字典
|
|
369
|
+
if 'domain' in cookie_dict:
|
|
370
|
+
self.add_cookie_from_dict(cookie_dict)
|
|
371
|
+
else:
|
|
372
|
+
self.cookies.set(**cookie_dict)
|
|
373
|
+
else:
|
|
374
|
+
logger.warning(f"无法设置cookie: {cookie_dict}")
|
|
375
|
+
elif isinstance(cookies, dict):
|
|
376
|
+
# 如果是简单的name-value字典
|
|
377
|
+
self.cookies.update(requests.utils.cookiejar_from_dict(cookies))
|
|
378
|
+
elif isinstance(cookies, str):
|
|
379
|
+
# 尝试从字符串解析
|
|
380
|
+
self._set_cookies_from_string(cookies)
|
|
381
|
+
|
|
382
|
+
def _set_cookies_from_string(self, cookie_string, domain=None):
|
|
383
|
+
"""从字符串设置cookies
|
|
384
|
+
|
|
385
|
+
Args:
|
|
386
|
+
cookie_string: Cookie字符串,例如 "name1=value1; name2=value2"
|
|
387
|
+
domain: 可选,cookie所属的域名
|
|
388
|
+
"""
|
|
389
|
+
if not cookie_string:
|
|
390
|
+
return
|
|
391
|
+
|
|
392
|
+
pairs = cookie_string.split(';')
|
|
393
|
+
for pair in pairs:
|
|
394
|
+
if '=' not in pair:
|
|
395
|
+
continue
|
|
396
|
+
|
|
397
|
+
name, value = pair.split('=', 1)
|
|
398
|
+
name = name.strip()
|
|
399
|
+
value = value.strip()
|
|
400
|
+
|
|
401
|
+
if domain:
|
|
402
|
+
self.cookies.set(name, value, domain=domain)
|
|
403
|
+
else:
|
|
404
|
+
self.cookies.set(name, value)
|
|
405
|
+
|
|
406
|
+
def get_cookies_for_domain(self, domain):
|
|
407
|
+
"""获取指定域名下的cookie的字典对象"""
|
|
408
|
+
return {cookie.name: cookie.value for cookie in self.cookies if domain in cookie.domain}
|
|
409
|
+
|
|
410
|
+
def get_cookies_string(self, domain=None):
|
|
411
|
+
"""获取适合HTTP请求的Cookie字符串
|
|
412
|
+
|
|
413
|
+
Args:
|
|
414
|
+
domain: 可选,限制只返回指定域名的cookie
|
|
415
|
+
|
|
416
|
+
Returns:
|
|
417
|
+
str: 格式为 "name1=value1; name2=value2" 的cookie字符串
|
|
418
|
+
"""
|
|
419
|
+
if domain:
|
|
420
|
+
cookies = self.get_cookies_for_domain(domain)
|
|
421
|
+
return '; '.join([f"{name}={value}" for name, value in cookies.items()])
|
|
422
|
+
else:
|
|
423
|
+
return '; '.join([f"{cookie.name}={cookie.value}" for cookie in self.cookies])
|
|
424
|
+
|
|
425
|
+
def log_request_and_response(self, request, response, proxies=None, duration=None):
|
|
426
|
+
"""记录请求和响应信息,并添加到请求历史"""
|
|
427
|
+
parsed_url = urlparse(request.url)
|
|
428
|
+
path = parsed_url.path
|
|
429
|
+
|
|
430
|
+
# 构建请求记录
|
|
431
|
+
request_record = {
|
|
432
|
+
'timestamp': time.time(),
|
|
433
|
+
'method': request.method,
|
|
434
|
+
'url': request.url,
|
|
435
|
+
'path': path,
|
|
436
|
+
'status_code': response.status_code,
|
|
437
|
+
'response_url': response.url,
|
|
438
|
+
'duration': round(duration, 3) if duration else None,
|
|
439
|
+
'proxies': proxies,
|
|
440
|
+
'redirects': len(response.history),
|
|
441
|
+
'request_headers': dict(request.headers),
|
|
442
|
+
'response_headers': dict(response.headers),
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
# 根据配置决定是否记录响应内容
|
|
446
|
+
current_type = response.headers.get('content-type', "").lower()
|
|
447
|
+
if self.print_log:
|
|
448
|
+
# 限制响应内容长度避免内存问题
|
|
449
|
+
max_text_length = 500
|
|
450
|
+
try:
|
|
451
|
+
if len(response.text) > max_text_length:
|
|
452
|
+
request_record['response_text'] = response.text[:max_text_length] + "..."
|
|
453
|
+
else:
|
|
454
|
+
request_record['response_text'] = response.text
|
|
455
|
+
except Exception as e:
|
|
456
|
+
request_record['response_text'] = f"获取响应文本失败: {str(e)}"
|
|
457
|
+
|
|
458
|
+
# 添加到历史记录
|
|
459
|
+
self.request_history.append(request_record)
|
|
460
|
+
|
|
461
|
+
# 限制历史记录大小
|
|
462
|
+
if len(self.request_history) > self.max_history_size:
|
|
463
|
+
self.request_history.pop(0)
|
|
464
|
+
|
|
465
|
+
# 构建日志消息
|
|
466
|
+
if proxies:
|
|
467
|
+
log_msg = f"请求: {path}, 方法: {request.method}, 状态码: {response.status_code}, 代理: {proxies}"
|
|
468
|
+
else:
|
|
469
|
+
log_msg = f"请求: {path}, 方法: {request.method}, 状态码: {response.status_code}"
|
|
470
|
+
|
|
471
|
+
if duration:
|
|
472
|
+
log_msg += f", 耗时: {round(duration, 3)}s"
|
|
473
|
+
|
|
474
|
+
if len(response.history) > 0:
|
|
475
|
+
log_msg += f", 重定向次数: {len(response.history)}"
|
|
476
|
+
|
|
477
|
+
# 记录响应文本(如果配置允许)
|
|
478
|
+
if self.print_log and not ('text/html' in current_type or "application/javascript" in current_type):
|
|
479
|
+
try:
|
|
480
|
+
log_msg += f", 响应内容: {response.text[:200]}..."
|
|
481
|
+
except:
|
|
482
|
+
log_msg += ", 无法获取响应内容"
|
|
483
|
+
if self.print_log:
|
|
484
|
+
logger.info(log_msg)
|
|
485
|
+
|
|
486
|
+
def get_request_history(self, limit=None, filter_func=None):
|
|
487
|
+
"""获取请求历史记录
|
|
488
|
+
|
|
489
|
+
Args:
|
|
490
|
+
limit: 限制返回的记录数量
|
|
491
|
+
filter_func: 过滤函数,接收记录作为参数,返回True/False
|
|
492
|
+
|
|
493
|
+
Returns:
|
|
494
|
+
过滤和限制后的请求历史记录列表
|
|
495
|
+
"""
|
|
496
|
+
history = self.request_history
|
|
497
|
+
|
|
498
|
+
if filter_func:
|
|
499
|
+
history = [record for record in history if filter_func(record)]
|
|
500
|
+
|
|
501
|
+
if limit and limit < len(history):
|
|
502
|
+
history = history[-limit:]
|
|
503
|
+
|
|
504
|
+
return history
|
|
505
|
+
|
|
506
|
+
def export_request_chain(self, filepath=None, limit=None):
|
|
507
|
+
"""导出请求链到文件
|
|
508
|
+
|
|
509
|
+
Args:
|
|
510
|
+
filepath: 导出文件路径,默认为"request_chain_{session_id}.json"
|
|
511
|
+
limit: 限制导出的记录数量
|
|
512
|
+
|
|
513
|
+
Returns:
|
|
514
|
+
导出文件的路径
|
|
515
|
+
"""
|
|
516
|
+
if not filepath:
|
|
517
|
+
filepath = f"{self.work_dir}/request_chain_{self._id}.json"
|
|
518
|
+
|
|
519
|
+
history = self.get_request_history(limit=limit)
|
|
520
|
+
|
|
521
|
+
os.makedirs(os.path.dirname(filepath), exist_ok=True)
|
|
522
|
+
|
|
523
|
+
with open(filepath, 'w', encoding='utf-8') as f:
|
|
524
|
+
json.dump(history, f, ensure_ascii=False, indent=2)
|
|
525
|
+
|
|
526
|
+
return filepath
|
|
527
|
+
|
|
528
|
+
def clear_history(self):
|
|
529
|
+
"""清除请求历史"""
|
|
530
|
+
self.request_history = []
|
|
531
|
+
|
|
532
|
+
def _load_file_lines(self, file_path, default_values=None):
|
|
533
|
+
"""从文件加载行数据,如果文件不存在则返回默认值
|
|
534
|
+
|
|
535
|
+
Args:
|
|
536
|
+
file_path: 文件路径
|
|
537
|
+
default_values: 如果文件不存在或为空,返回的默认值列表
|
|
538
|
+
|
|
539
|
+
Returns:
|
|
540
|
+
从文件读取的行列表,或默认值列表
|
|
541
|
+
"""
|
|
542
|
+
if default_values is None:
|
|
543
|
+
default_values = []
|
|
544
|
+
|
|
545
|
+
try:
|
|
546
|
+
if os.path.exists(file_path):
|
|
547
|
+
with open(file_path, 'r', encoding='utf-8') as f:
|
|
548
|
+
lines = [line.strip() for line in f if line.strip()]
|
|
549
|
+
if lines:
|
|
550
|
+
return lines
|
|
551
|
+
return default_values
|
|
552
|
+
except Exception as e:
|
|
553
|
+
logger.warning(f"从文件 {file_path} 加载数据时出错: {e}")
|
|
554
|
+
return default_values
|
|
555
|
+
|
|
556
|
+
def set_print_log(self, print_log):
|
|
557
|
+
"""设置是否记录响应文本"""
|
|
558
|
+
self.print_log = print_log
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
if __name__ == "__main__":
|
|
562
|
+
# 示例:保存和加载带有域名分组cookie的会话
|
|
563
|
+
session = RequestSession()
|
|
564
|
+
session.initialize_session()
|
|
565
|
+
session.set_proxy(use_proxy=True, random_proxy=False)
|
|
566
|
+
print(session.proxies_list)
|
|
567
|
+
logger.info(session.proxies_list)
|
|
568
|
+
|
|
569
|
+
response = session.get("https://tls.peet.ws/api/all")
|
|
570
|
+
|
|
571
|
+
response = session.get("https://www.twitch.tv")
|
|
572
|
+
response = session.get("https://google.com")
|
|
573
|
+
response = session.get("https://passport.twitch.tv")
|
|
574
|
+
session.export_request_chain()
|
|
575
|
+
# print(response.text)
|
|
576
|
+
|
|
577
|
+
session.save_session()
|
|
578
|
+
|
|
579
|
+
# # 设置不同域名的cookie
|
|
580
|
+
# session.cookies.set('test_cookie1', 'value1', domain='example.com')
|
|
581
|
+
# session.cookies.set('test_cookie2', 'value2', domain='example.com')
|
|
582
|
+
# session.cookies.set('other_cookie', 'other_value', domain='other.com')
|
|
583
|
+
|
|
584
|
+
# # 保存会话
|
|
585
|
+
# saved_path = session.save_session(_id="test_session")
|
|
586
|
+
# print(f"会话已保存到: {saved_path}")
|
|
587
|
+
|
|
588
|
+
# # 加载会话
|
|
589
|
+
# saved_path = "tmp/http_session/test_session.json"
|
|
590
|
+
# loaded_session = RequestSession.load_session(saved_path)
|
|
591
|
+
|
|
592
|
+
# # 验证cookie是否按域名加载
|
|
593
|
+
# print("example.com的cookies:", loaded_session.get_cookies_for_domain('example.com'))
|
|
594
|
+
# print("other.com的cookies:", loaded_session.get_cookies_for_domain('other.com'))
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
def get_liking_users(tweet_id):
|
|
598
|
+
# 初始化新建session
|
|
599
|
+
session = RequestSession()
|
|
600
|
+
session.print_log = True
|
|
601
|
+
session.initialize_session(random_init=True)
|
|
602
|
+
session.set_proxy(use_proxy=True, random_proxy=False)
|
|
603
|
+
|
|
604
|
+
# # 加载已有session
|
|
605
|
+
# saved_path = "tmp/http_session/test_x.json"
|
|
606
|
+
# session = RequestSession.load_session(saved_path)
|
|
607
|
+
session.get("https://twitter.com/")
|
|
608
|
+
|
|
609
|
+
url = f"https://api.twitter.com/2/tweets/{tweet_id}/liking_users"
|
|
610
|
+
headers = {
|
|
611
|
+
"Authorization": "Bearer YOUR_ACCESS_TOKEN"
|
|
612
|
+
}
|
|
613
|
+
response = session.get(url, headers=headers)
|
|
614
|
+
# session.save_session(_id="test_x")
|
|
615
|
+
session.save_session()
|
|
616
|
+
if response.status_code == 200:
|
|
617
|
+
return response.json()['data']
|
|
618
|
+
else:
|
|
619
|
+
return "Error: " + response.text
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
# # 使用示例
|
|
623
|
+
# tweet_id = '1234567890123456789' # 示例推文ID
|
|
624
|
+
# liking_users = get_liking_users(tweet_id)
|
|
625
|
+
# print(liking_users)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6
|
|
2
|
+
en-US,en;q=0.9,fr;q=0.8,fr-FR;q=0.7,es;q=0.6
|
|
3
|
+
fr-FR,fr;q=0.9,en;q=0.8,en-US;q=0.7,de;q=0.6
|
|
4
|
+
de-DE,de;q=0.9,en;q=0.8,en-GB;q=0.7,fr;q=0.6
|
|
5
|
+
es-ES,es;q=0.9,en;q=0.8,en-US;q=0.7,it;q=0.6
|
|
6
|
+
it-IT,it;q=0.9,en;q=0.8,en-GB;q=0.7,fr;q=0.6
|
|
7
|
+
ja-JP,ja;q=0.9,en;q=0.8,en-US;q=0.7,zh-CN;q=0.6
|
|
8
|
+
ru-RU,ru;q=0.9,en;q=0.8,en-GB;q=0.7,de;q=0.6
|
|
9
|
+
pt-BR,pt;q=0.9,en;q=0.8,en-US;q=0.7,es;q=0.6
|
|
10
|
+
ko-KR,ko;q=0.9,en;q=0.8,en-US;q=0.7,ja;q=0.6
|
|
11
|
+
nl-NL,nl;q=0.9,en;q=0.8,en-GB;q=0.7,de;q=0.6
|
|
12
|
+
sv-SE,sv;q=0.9,en;q=0.8,en-GB;q=0.7,no;q=0.6
|
|
13
|
+
pl-PL,pl;q=0.9,en;q=0.8,en-US;q=0.7,de;q=0.6
|
|
14
|
+
tr-TR,tr;q=0.9,en;q=0.8,en-GB;q=0.7,de;q=0.6
|
|
15
|
+
da-DK,da;q=0.9,en;q=0.8,en-GB;q=0.7,sv;q=0.6
|
|
16
|
+
fi-FI,fi;q=0.9,en;q=0.8,en-GB;q=0.7,sv;q=0.6
|
|
17
|
+
he-IL,he;q=0.9,en;q=0.8,en-US;q=0.7,ru;q=0.6
|
|
18
|
+
ar-SA,ar;q=0.9,en;q=0.8,en-GB;q=0.7,fr;q=0.6
|
|
19
|
+
hi-IN,hi;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6
|
|
20
|
+
th-TH,th;q=0.9,en;q=0.8,en-US;q=0.7,zh-CN;q=0.6
|
|
21
|
+
cs-CZ,cs;q=0.9,en;q=0.8,en-GB;q=0.7,de;q=0.6
|
|
22
|
+
hu-HU,hu;q=0.9,en;q=0.8,en-US;q=0.7,de;q=0.6
|
|
23
|
+
vi-VN,vi;q=0.9,en;q=0.8,en-US;q=0.7,zh-CN;q=0.6
|
|
24
|
+
uk-UA,uk;q=0.9,en;q=0.8,en-GB;q=0.7,ru;q=0.6
|
|
25
|
+
id-ID,id;q=0.9,en;q=0.8,en-US;q=0.7,nl;q=0.6
|
|
26
|
+
ms-MY,ms;q=0.9,en;q=0.8,en-GB;q=0.7,id;q=0.6
|
|
27
|
+
no-NO,no;q=0.9,en;q=0.8,en-GB;q=0.7,sv;q=0.6
|
|
28
|
+
ro-RO,ro;q=0.9,en;q=0.8,en-US;q=0.7,hu;q=0.6
|
|
29
|
+
sk-SK,sk;q=0.9,en;q=0.8,en-GB;q=0.7,cs;q=0.6
|
|
30
|
+
el-GR,el;q=0.9,en;q=0.8,en-US;q=0.7,fr;q=0.6
|
|
31
|
+
bg-BG,bg;q=0.9,en;q=0.8,en-GB;q=0.7,ru;q=0.6
|
|
32
|
+
sr-RS,sr;q=0.9,en;q=0.8,en-US;q=0.7,hr;q=0.6
|
|
33
|
+
ca-ES,ca;q=0.9,es;q=0.8,en;q=0.7,fr;q=0.6
|
|
34
|
+
zh-TW,zh;q=0.9,en;q=0.8,en-US;q=0.7,zh-CN;q=0.6
|
|
35
|
+
fa-IR,fa;q=0.9,en;q=0.8,en-GB;q=0.7,ar;q=0.6
|
|
36
|
+
et-EE,et;q=0.9,en;q=0.8,en-GB;q=0.7,fi;q=0.6
|
|
37
|
+
lv-LV,lv;q=0.9,en;q=0.8,en-US;q=0.7,ru;q=0.6
|
|
38
|
+
lt-LT,lt;q=0.9,en;q=0.8,en-GB;q=0.7,ru;q=0.6
|
|
39
|
+
hr-HR,hr;q=0.9,en;q=0.8,en-US;q=0.7,de;q=0.6
|
|
40
|
+
sl-SI,sl;q=0.9,en;q=0.8,en-GB;q=0.7,hr;q=0.6
|
|
41
|
+
en-AU,en;q=0.9,en-GB;q=0.8,en-US;q=0.7,fr;q=0.6
|
|
42
|
+
en-CA,en;q=0.9,en-US;q=0.8,en-GB;q=0.7,fr-CA;q=0.6
|
|
43
|
+
en-NZ,en;q=0.9,en-GB;q=0.8,en-US;q=0.7,mi;q=0.6
|
|
44
|
+
en-ZA,en;q=0.9,en-GB;q=0.8,en-US;q=0.7,af;q=0.6
|
|
45
|
+
en-IE,en;q=0.9,en-GB;q=0.8,en-US;q=0.7,ga;q=0.6
|
|
46
|
+
en-IN,en;q=0.9,en-GB;q=0.8,en-US;q=0.7,hi;q=0.6
|
|
47
|
+
en-PH,en;q=0.9,en-US;q=0.8,en-GB;q=0.7,tl;q=0.6
|
|
48
|
+
es-MX,es;q=0.9,es-ES;q=0.8,en;q=0.7,en-US;q=0.6
|
|
49
|
+
pt-PT,pt;q=0.9,pt-BR;q=0.8,en;q=0.7,en-GB;q=0.6
|
|
50
|
+
fr-CA,fr;q=0.9,fr-FR;q=0.8,en;q=0.7,en-CA;q=0.6
|
|
File without changes
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 OPR/68.0.3618.191
|
|
2
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36 Edg/83.0.478.61
|
|
3
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
4
|
+
Mozilla/5.0 (Windows NT 6.1; ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
5
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
6
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
7
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
8
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
9
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
10
|
+
Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
11
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 OPR/68.0.3618.191
|
|
12
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
13
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
14
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) coc_coc_browser/87.0.152 Chrome/81.0.4044.152 Safari/537.36
|
|
15
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
16
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
17
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
18
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
19
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
20
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36
|
|
21
|
+
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
|
|
22
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 OPR/68.0.3618.173
|
|
23
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36 Edg/83.0.478.61
|
|
24
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0
|
|
25
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36 Edg/83.0.478.61
|
|
26
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
27
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0
|
|
28
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
29
|
+
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36
|
|
30
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
31
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
32
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0
|
|
33
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0
|
|
34
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0
|
|
35
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
36
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0
|
|
37
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36 Edg/83.0.478.61
|
|
38
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
39
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
40
|
+
Mozilla/5.0 (Macintosh; PPC Mac OS X 10.12; rv:53.0) Gecko/20100101 Firefox/53.0
|
|
41
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
42
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0
|
|
43
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
44
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.119 Safari/537.36
|
|
45
|
+
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
46
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
47
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
48
|
+
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
49
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
50
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
51
|
+
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
52
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) coc_coc_browser/87.0.152 Chrome/81.0.4044.152 Safari/537.36
|
|
53
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
54
|
+
Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36
|
|
55
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
56
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.18247
|
|
57
|
+
Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36
|
|
58
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3599.0 Safari/537.36
|
|
59
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; rv:11.0) like Gecko
|
|
60
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3599.0 Safari/537.36
|
|
61
|
+
Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36
|
|
62
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
63
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3599.0 Safari/537.36
|
|
64
|
+
Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36
|
|
65
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; rv:11.0) like Gecko
|
|
66
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3599.0 Safari/537.36
|
|
67
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3599.0 Safari/537.36
|
|
68
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3599.0 Safari/537.36
|
|
69
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3599.0 Safari/537.36
|
|
70
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3599.0 Safari/537.36
|
|
71
|
+
Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
|
|
72
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; rv:11.0) like Gecko
|
|
73
|
+
Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36
|
|
74
|
+
Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
|
|
75
|
+
Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36
|
|
76
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3599.0 Safari/537.36
|
|
77
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.18247
|
|
78
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3599.0 Safari/537.36
|
|
79
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
80
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.18247
|
|
81
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3599.0 Safari/537.36
|
|
82
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.18247
|
|
83
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3599.0 Safari/537.36
|
|
84
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3599.0 Safari/537.36
|
|
85
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3599.0 Safari/537.36
|
|
86
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3599.0 Safari/537.36
|
|
87
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3599.0 Safari/537.36
|
|
88
|
+
Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36
|
|
89
|
+
Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
|
|
90
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3599.0 Safari/537.36
|
|
91
|
+
Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; rv:11.0) like Gecko
|
|
92
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
|
|
93
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4086.0 Safari/537.36
|
|
94
|
+
Mozilla/5.0 (X11; Linux i686 (x86_64)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4086.0 Safari/537.36
|
|
95
|
+
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4086.0 Safari/537.36
|
|
96
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4087.0 Safari/537.36
|
|
97
|
+
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4087.0 Safari/537.36
|
|
98
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4088.0 Safari/537.36
|
|
99
|
+
Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4086.0 Safari/537.36
|
|
100
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4089.0 Safari/537.36
|
|
101
|
+
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4089.0 Safari/537.36
|
|
102
|
+
Mozilla/5.0 (X11; CrOS x86_64 12974.2.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4089.0 Safari/537.36
|
|
103
|
+
Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4089.0 Safari/537.36
|
|
104
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4086.0 Safari/537.36
|
|
105
|
+
Mozilla/5.0 (X11; Linux i686 (x86_64)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4086.0 Safari/537.36
|
|
106
|
+
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4086.0 Safari/537.36
|
|
107
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4087.0 Safari/537.36
|
|
108
|
+
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4087.0 Safari/537.36
|
|
109
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4088.0 Safari/537.36
|
|
110
|
+
Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4086.0 Safari/537.36
|
|
111
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4089.0 Safari/537.36
|
|
112
|
+
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4089.0 Safari/537.36
|
|
113
|
+
Mozilla/5.0 (X11; CrOS x86_64 12974.2.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4089.0 Safari/537.36
|
|
114
|
+
Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4089.0 Safari/537.36
|
|
115
|
+
Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4089.0 Safari/537.36
|
|
116
|
+
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4090.0 Safari/537.36
|
|
117
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4091.0 Safari/537.36
|
|
118
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4090.0 Safari/537.36
|
|
119
|
+
Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4091.0 Safari/537.36
|
|
120
|
+
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4091.0 Safari/537.36
|
|
121
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4092.0 Safari/537.36
|
|
122
|
+
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4092.0 Safari/537.36
|
|
123
|
+
Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4090.0 Safari/537.36
|
|
124
|
+
Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4091.0 Safari/537.36
|
|
125
|
+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4093.0 Safari/537.36
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: rqsession
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python requests session wrapper with advanced features for proxy management, session persistence, cookies auto update and request logging.
|
|
5
|
+
Author: leftmonster
|
|
6
|
+
Requires-Python: >=3.8,<4.0
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Requires-Dist: requests (>=2.32.3,<3.0.0)
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# RequestSession
|
|
18
|
+
|
|
19
|
+
A powerful Python requests session wrapper with advanced features for proxy management, session persistence, and request logging.
|
|
20
|
+
|
|
21
|
+
[](https://pypi.org/project/rqsession/)
|
|
22
|
+
[](https://pypi.org/project/rqsession/)
|
|
23
|
+
[](https://github.com/yourusername/rqsession/blob/main/LICENSE)
|
|
24
|
+
|
|
25
|
+
## Features
|
|
26
|
+
|
|
27
|
+
- 🌐 Proxy Management: Easy configuration of proxies with support for random rotation or fixed proxy per session
|
|
28
|
+
- 💾 Session Persistence: Save and load sessions with cookies and headers, eliminating repetitive setup
|
|
29
|
+
- 📝 Comprehensive Logging: Detailed request and response tracking with intelligent formatting and visualization
|
|
30
|
+
- 🍪 Advanced Cookie Handling: Automatic domain-based cookie management and updates across different domains
|
|
31
|
+
- 🔄 Request History: Track all requests with detailed metadata and exportable request chains for analysis
|
|
32
|
+
- 🔧 Auto Headers: Automatic configuration of common headers like Host, Referer, and Origin, preventing resource access issues across different domains
|
|
33
|
+
- 🚀 Simplified Workflow: Eliminates the hassle of manually building request signatures and managing session state
|
|
34
|
+
|
|
35
|
+
These features make RequestSession an ideal tool for web scraping, API testing, and automated browsing tasks where consistency and detailed tracking are essential.
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install rqsession
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Quick Start
|
|
44
|
+
|
|
45
|
+
- simple 1
|
|
46
|
+
```python
|
|
47
|
+
from rqsession import RequestSession
|
|
48
|
+
|
|
49
|
+
# Create a new session
|
|
50
|
+
session = RequestSession()
|
|
51
|
+
# Initialize with random base headers
|
|
52
|
+
session.initialize_session()
|
|
53
|
+
# print log
|
|
54
|
+
session.print_log = True
|
|
55
|
+
|
|
56
|
+
print("Current session headers:", session.headers)
|
|
57
|
+
session.get("https://google.com")
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+

|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from rqsession import RequestSession
|
|
65
|
+
|
|
66
|
+
# Create a new session
|
|
67
|
+
session = RequestSession()
|
|
68
|
+
|
|
69
|
+
# Initialize with random headers
|
|
70
|
+
session.initialize_session(random_init=True)
|
|
71
|
+
|
|
72
|
+
# Enable proxy
|
|
73
|
+
session.set_proxy(use_proxy=True, random_proxy=True)
|
|
74
|
+
|
|
75
|
+
# Make a request
|
|
76
|
+
response = session.get("https://example.com")
|
|
77
|
+
|
|
78
|
+
# Save the session for later use
|
|
79
|
+
session.save_session(_id="my_session")
|
|
80
|
+
|
|
81
|
+
# Load a saved session
|
|
82
|
+
loaded_session = RequestSession.load_session("tmp/http_session/my_session.json")
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Advanced Usage
|
|
86
|
+
|
|
87
|
+
### Proxy Configuration
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
# Configure a session with custom proxy settings
|
|
91
|
+
session = RequestSession(
|
|
92
|
+
config={
|
|
93
|
+
"host": "127.0.0.1",
|
|
94
|
+
"port": "8080",
|
|
95
|
+
"enabled": True,
|
|
96
|
+
"random_proxy": True,
|
|
97
|
+
"proxy_file": "path/to/proxies.txt"
|
|
98
|
+
}
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
# Use a custom proxy method
|
|
102
|
+
def get_my_proxy():
|
|
103
|
+
return "http://user:pass@proxy.example.com:8080"
|
|
104
|
+
|
|
105
|
+
session = RequestSession(proxy_method=get_my_proxy)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Session Management
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
# Save the current session
|
|
112
|
+
session.save_session(_id="my_saved_session")
|
|
113
|
+
|
|
114
|
+
# Load a previously saved session
|
|
115
|
+
loaded_session = RequestSession.load_session("tmp/http_session/my_saved_session.json")
|
|
116
|
+
|
|
117
|
+
# Get all cookies for a specific domain
|
|
118
|
+
domain_cookies = session.get_cookies_for_domain("example.com")
|
|
119
|
+
|
|
120
|
+
# Export cookies as a string for use in other tools
|
|
121
|
+
cookie_string = session.get_cookies_string(domain="example.com")
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Request History and Logging
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
# Enable detailed logging
|
|
128
|
+
session.set_print_log(True)
|
|
129
|
+
|
|
130
|
+
# Make some requests
|
|
131
|
+
session.get("https://example.com/page1")
|
|
132
|
+
session.post("https://example.com/api", json={"key": "value"})
|
|
133
|
+
|
|
134
|
+
# Get the last 5 requests
|
|
135
|
+
recent_requests = session.get_request_history(limit=5)
|
|
136
|
+
|
|
137
|
+
# Filter requests by status code
|
|
138
|
+
successful_requests = session.get_request_history(
|
|
139
|
+
filter_func=lambda r: r["status_code"] == 200
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
# Export request history to a file
|
|
143
|
+
session.export_request_chain(filepath="request_history.json")
|
|
144
|
+
|
|
145
|
+
# Clear request history
|
|
146
|
+
session.clear_history()
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Cookie Management
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
# Set cookies from a dictionary
|
|
153
|
+
session.set_cookies({
|
|
154
|
+
"session_id": "abc123",
|
|
155
|
+
"user_preferences": "dark_mode"
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
# Set cookies with full details
|
|
159
|
+
session.set_cookies([
|
|
160
|
+
{
|
|
161
|
+
"name": "session_id",
|
|
162
|
+
"value": "abc123",
|
|
163
|
+
"domain": "example.com",
|
|
164
|
+
"path": "/",
|
|
165
|
+
"secure": True,
|
|
166
|
+
"httponly": True
|
|
167
|
+
}
|
|
168
|
+
])
|
|
169
|
+
|
|
170
|
+
# Set cookies from a string
|
|
171
|
+
session.set_cookies("name1=value1; name2=value2")
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Configuration
|
|
175
|
+
|
|
176
|
+
The RequestSession can be configured with the following options:
|
|
177
|
+
|
|
178
|
+
| Option | Description | Default |
|
|
179
|
+
|--------|-------------|---------|
|
|
180
|
+
| host | Proxy host | From config.ini |
|
|
181
|
+
| port | Proxy port | From config.ini |
|
|
182
|
+
| enabled | Enable proxy | Based on config.ini |
|
|
183
|
+
| random_proxy | Rotate proxies randomly | False |
|
|
184
|
+
| print_log | Enable detailed logging | Based on config.ini |
|
|
185
|
+
| proxy_file | File with proxy list | "static/proxies.txt" |
|
|
186
|
+
| max_history_size | Maximum number of requests to keep in history | 100 |
|
|
187
|
+
| auto_headers | Automatically set common headers | False |
|
|
188
|
+
| user_agents_file | File with user agents | "static/useragents.txt" |
|
|
189
|
+
| languages_file | File with Accept-Language values | "static/language.txt" |
|
|
190
|
+
| work_path | Path for saving sessions and logs | "tmp/http_session" |
|
|
191
|
+
|
|
192
|
+
## Contributing
|
|
193
|
+
|
|
194
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
195
|
+
|
|
196
|
+
## License
|
|
197
|
+
|
|
198
|
+
This project is licensed under the Apache License - see the LICENSE file for details.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
rqsession/__init__.py,sha256=MhqhXbbxv_hk-kN4cSpRgnst3h2QUQRicy5uv8xGBhw,109
|
|
2
|
+
rqsession/config.ini,sha256=QI6ROdxjQEp-C3taf3rb0GGvLeK9-AodzzD0kSmcdtA,63
|
|
3
|
+
rqsession/config_util.py,sha256=hzJlqBWYjRF_RhjtjVtcrWcUADvzghuQSpEJJKmcy6s,674
|
|
4
|
+
rqsession/logger.py,sha256=Gk32EgRLZ4nFzRyps-Rvyj38KMkFyHRVsY2vc9MWdRU,334
|
|
5
|
+
rqsession/request_session.py,sha256=YWJsguz-qwzihAgLcPngzSW966H50WX3HHqhqPVstRA,23531
|
|
6
|
+
rqsession/static/language.txt,sha256=MXPXqD0_gbvYmpHTMCIMUdW21uW650V9B7lDtuqoISc,2346
|
|
7
|
+
rqsession/static/proxies.txt,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
rqsession/static/useragents.txt,sha256=YtBvuRp-x4lf6RHLEqQg2VOCNfk1nwM3zoDXw7polus,13988
|
|
9
|
+
rqsession-0.1.0.dist-info/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
|
|
10
|
+
rqsession-0.1.0.dist-info/METADATA,sha256=7a64UJfdYGlt9JLMULI1C2-bc7RyNhU1Mr75cRB17BA,6071
|
|
11
|
+
rqsession-0.1.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
12
|
+
rqsession-0.1.0.dist-info/RECORD,,
|