forked from Boris-code/feapder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebdirver.py
More file actions
81 lines (73 loc) · 2.51 KB
/
webdirver.py
File metadata and controls
81 lines (73 loc) · 2.51 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# -*- coding: utf-8 -*-
"""
Created on 2022/9/7 4:27 PM
---------
@summary:
---------
@author: Boris
@email: boris_liu@foxmail.com
"""
import abc
from feapder import setting
class InterceptRequest:
def __init__(self, url, data, headers):
self.url = url
self.data = data
self.headers = headers
class InterceptResponse:
def __init__(self, request: InterceptRequest, url, headers, content, status_code):
self.request = request
self.url = url
self.headers = headers
self.content = content
self.status_code = status_code
class WebDriver:
def __init__(
self,
load_images=True,
user_agent=None,
proxy=None,
headless=False,
driver_type=None,
timeout=16,
window_size=(1024, 800),
executable_path=None,
custom_argument=None,
download_path=None,
auto_install_driver=True,
use_stealth_js=True,
**kwargs,
):
"""
webdirver 封装,支持chrome、phantomjs 和 firefox
Args:
load_images: 是否加载图片
user_agent: 字符串 或 无参函数,返回值为user_agent
proxy: xxx.xxx.xxx.xxx:xxxx 或 无参函数,返回值为代理地址
headless: 是否启用无头模式
driver_type: CHROME 或 PHANTOMJS,FIREFOX
timeout: 请求超时时间
window_size: # 窗口大小
executable_path: 浏览器路径,默认为默认路径
custom_argument: 自定义参数 用于webdriver.Chrome(options=chrome_options, **kwargs)
download_path: 文件下载保存路径;如果指定,不再出现“保留”“放弃”提示,仅对Chrome有效
auto_install_driver: 自动下载浏览器驱动 支持chrome 和 firefox
use_stealth_js: 使用stealth.min.js隐藏浏览器特征
**kwargs:
"""
self._load_images = load_images
self._user_agent = user_agent or setting.DEFAULT_USERAGENT
self._proxy = proxy
self._headless = headless
self._timeout = timeout
self._window_size = window_size
self._executable_path = executable_path
self._custom_argument = custom_argument
self._download_path = download_path
self._auto_install_driver = auto_install_driver
self._use_stealth_js = use_stealth_js
self._driver_type = driver_type
self._kwargs = kwargs
@abc.abstractmethod
def quit(self):
pass