Selenium-Wire 开源项目教程

Selenium-Wire 开源项目教程

selenium-wireExtends Selenium's Python bindings to give you the ability to inspect requests made by the browser.项目地址:https://gitcode.com/gh_mirrors/se/selenium-wire

1. 项目的目录结构及介绍

Selenium-Wire 是一个用于拦截和检查浏览器发出的 HTTP 请求的工具。以下是其主要目录结构及其功能介绍:

selenium-wire/
├── docs/
│   ├── conf.py
│   ├── index.rst
│   └── ...
├── seleniumwire/
│   ├── backend.py
│   ├── certutils.py
│   ├── proxy/
│   │   ├── cert.py
│   │   ├── handler.py
│   │   └── ...
│   ├── request.py
│   ├── storage.py
│   └── ...
├── tests/
│   ├── test_backend.py
│   ├── test_request.py
│   └── ...
├── setup.py
├── README.md
└── ...
  • docs/: 包含项目文档的配置文件和文档源文件。
  • seleniumwire/: 核心代码目录,包含代理、请求处理、存储等相关模块。
  • tests/: 包含项目的测试代码。
  • setup.py: 用于安装项目的配置文件。
  • README.md: 项目介绍和使用说明。

2. 项目的启动文件介绍

Selenium-Wire 的启动文件主要是 seleniumwire/__init__.py,它初始化了 Selenium-Wire 的核心功能,并提供了与 Selenium WebDriver 的集成。

from .webdriver import WebDriver
from .proxy.request import RequestInterceptor
from .proxy.storage import RequestStorage
from .proxy.handler import InterceptRequestHandler
from .proxy.cert import CertificateManager
from .backend import MitmProxy
from .options import Options

__version__ = '4.7.2'

def get_options(options=None):
    return Options.default(options)

def create_proxy(options=None):
    options = get_options(options)
    cert_manager = CertificateManager(options)
    storage = RequestStorage(options)
    interceptor = RequestInterceptor(options, storage)
    backend = MitmProxy(options, cert_manager, interceptor)
    return backend

def WebDriver(*args, **kwargs):
    return WebDriver(*args, **kwargs)
  • WebDriver: 集成 Selenium WebDriver 的类。
  • RequestInterceptor: 请求拦截器。
  • RequestStorage: 请求存储器。
  • InterceptRequestHandler: 请求处理程序。
  • CertificateManager: 证书管理器。
  • MitmProxy: 中间人代理。
  • Options: 配置选项。

3. 项目的配置文件介绍

Selenium-Wire 的配置文件主要是 seleniumwire/options.py,它定义了项目的配置选项。

class Options:
    def __init__(self, options=None):
        self.options = options or {}

    @classmethod
    def default(cls, options=None):
        default_options = {
            'addr': '127.0.0.1',
            'port': 12345,
            'proxy': {
                'http': 'http://localhost:8080',
                'https': 'https://localhost:8080',
                'no_proxy': 'localhost,127.0.0.1'
            },
            'request_storage_base_dir': None,
            'disable_encoding': False,
            'enable_har': False,
            'ignore_http_methods': [],
            'max_body_size': 0,
            'mitm_host': '127.0.0.1',
            'mitm_port': 8080,
            'ca_cert': None,
            'ca_key': None,
            'ca_passphrase': None,
            'verify_ssl': True,
            'suppress_connection_errors': True,
            'backend': 'mitmproxy',
            'request_storage': 'memory',
            'scopes': [],
            'headers': {},
            'params': {},
            'cookies': {},
            'rewrite': [],
            'ignore_http_methods': [],
            'disable_capture': False,
            'disable_encoding': False,
            'enable_har': False,
            'max_body_size': 0,
            'mitm_host

selenium-wireExtends Selenium's Python bindings to give you the ability to inspect requests made by the browser.项目地址:https://gitcode.com/gh_mirrors/se/selenium-wire

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

马品向

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值