| 29 | |
| 30 | |
| 31 | class WebDriver: |
| 32 | def __init__( |
| 33 | self, |
| 34 | load_images=True, |
| 35 | user_agent=None, |
| 36 | proxy=None, |
| 37 | headless=False, |
| 38 | driver_type=None, |
| 39 | timeout=16, |
| 40 | window_size=(1024, 800), |
| 41 | executable_path=None, |
| 42 | custom_argument=None, |
| 43 | download_path=None, |
| 44 | auto_install_driver=True, |
| 45 | use_stealth_js=True, |
| 46 | **kwargs, |
| 47 | ): |
| 48 | """ |
| 49 | webdirver 封装,支持chrome、phantomjs 和 firefox |
| 50 | Args: |
| 51 | load_images: 是否加载图片 |
| 52 | user_agent: 字符串 或 无参函数,返回值为user_agent |
| 53 | proxy: xxx.xxx.xxx.xxx:xxxx 或 无参函数,返回值为代理地址 |
| 54 | headless: 是否启用无头模式 |
| 55 | driver_type: CHROME,EDGE 或 PHANTOMJS,FIREFOX |
| 56 | timeout: 请求超时时间 |
| 57 | window_size: # 窗口大小 |
| 58 | executable_path: 浏览器路径,默认为默认路径 |
| 59 | custom_argument: 自定义参数 用于webdriver.Chrome(options=chrome_options, **kwargs) |
| 60 | download_path: 文件下载保存路径;如果指定,不再出现“保留”“放弃”提示,仅对Chrome有效 |
| 61 | auto_install_driver: 自动下载浏览器驱动 支持chrome 和 firefox |
| 62 | use_stealth_js: 使用stealth.min.js隐藏浏览器特征 |
| 63 | **kwargs: |
| 64 | """ |
| 65 | self._load_images = load_images |
| 66 | self._user_agent = user_agent or setting.DEFAULT_USERAGENT |
| 67 | self._proxy = proxy |
| 68 | self._headless = headless |
| 69 | self._timeout = timeout |
| 70 | self._window_size = window_size |
| 71 | self._executable_path = executable_path |
| 72 | self._custom_argument = custom_argument |
| 73 | self._download_path = download_path |
| 74 | self._auto_install_driver = auto_install_driver |
| 75 | self._use_stealth_js = use_stealth_js |
| 76 | self._driver_type = driver_type |
| 77 | self._kwargs = kwargs |
| 78 | |
| 79 | @abc.abstractmethod |
| 80 | def quit(self): |
| 81 | pass |
no outgoing calls