Skip to content
This repository was archived by the owner on Jan 3, 2024. It is now read-only.

Commit bccb8e8

Browse files
committed
README updates
1 parent fb3778d commit bccb8e8

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

Diff for: README.rst

+14-9
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ Request objects have the following attributes.
249249
A dictionary-like object of request headers. Headers are case-insensitive and duplicates are permitted. Asking for ``request.headers['user-agent']`` will return the value of the ``User-Agent`` header. If you wish to replace a header, make sure you delete the existing header first with ``del request.headers['header-name']``, otherwise you'll create a duplicate.
250250

251251
``method``
252-
The HTTP method type, e.g. ``GET`` or ``POST``.
252+
The HTTP method type, e.g. ``GET`` or ``POST`` etc.
253253

254254
``params``
255255
A dictionary of request parameters. If a parameter with the same name appears more than once in the request, it's value in the dictionary will be a list.
@@ -289,15 +289,15 @@ Response objects have the following attributes.
289289
A dictionary-like object of response headers. Headers are case-insensitive and duplicates are permitted. Asking for ``response.headers['content-length']`` will return the value of the ``Content-Length`` header. If you wish to replace a header, make sure you delete the existing header first with ``del response.headers['header-name']``, otherwise you'll create a duplicate.
290290

291291
``reason``
292-
The reason phrase, e.g. ``OK`` or ``Not Found``.
292+
The reason phrase, e.g. ``OK`` or ``Not Found`` etc.
293293

294294
``status_code``
295-
The status code of the response, e.g. ``200`` or ``404``.
295+
The status code of the response, e.g. ``200`` or ``404`` etc.
296296

297297
Intercepting Requests and Responses
298298
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
299299

300-
Selenium Wire allows you to modify requests and responses on the fly using interceptors. An interceptor is a function that gets invoked with the requests and responses as they pass through Selenium Wire. Within an interceptor you can modify the request and response as you see fit.
300+
Selenium Wire allows you to modify requests and responses on the fly using interceptors. An interceptor is a function that gets invoked with requests and responses as they pass through Selenium Wire. Within an interceptor you can modify the request and response as you see fit.
301301

302302
You set your interceptor functions using the ``driver.request_interceptor`` and ``driver.response_interceptor`` attributes before you start using the driver. A request interceptor should accept a single argument for the request. A response interceptor should accept two arguments, one for the originating request and one for the response.
303303

@@ -310,6 +310,7 @@ Example: Add a request header
310310
request.headers['New-Header'] = 'Some Value'
311311
312312
driver.request_interceptor = interceptor
313+
driver.get(...)
313314
314315
# All requests will now contain New-Header
315316
@@ -327,6 +328,7 @@ Duplicate header names are permitted in an HTTP request, so before setting the r
327328
request.headers['Referer'] = 'some_referer' # Spoof the referer
328329
329330
driver.request_interceptor = interceptor
331+
driver.get(...)
330332
331333
# All requests will now use 'some_referer' for the referer
332334
@@ -340,6 +342,7 @@ Example: Add a response header
340342
response.headers['New-Header'] = 'Some Value'
341343
342344
driver.response_interceptor = interceptor
345+
driver.get(...)
343346
344347
# Responses from https://server.com/some/path will now contain New-Header
345348
@@ -356,6 +359,7 @@ Request parameters work differently to headers in that they are calculated when
356359
request.params = params
357360
358361
driver.request_interceptor = interceptor
362+
driver.get(...)
359363
360364
# foo=bar will be added to all requests
361365
@@ -381,6 +385,7 @@ Example: Update JSON in a POST request body
381385
request.headers['Content-Length'] = str(len(request.body))
382386
383387
driver.request_interceptor = interceptor
388+
driver.get(...)
384389
385390
Example: Block a request
386391
------------------------
@@ -395,6 +400,7 @@ You can use ``request.abort()`` to block a request and send an immediate respons
395400
request.abort()
396401
397402
driver.request_interceptor = interceptor
403+
driver.get(...)
398404
399405
# Requests for PNG, JPEG and GIF images will result in a 403 Forbidden
400406
@@ -414,6 +420,7 @@ You can use ``request.create_response()`` to send a custom reply back to the cli
414420
)
415421
416422
driver.request_interceptor = interceptor
423+
driver.get(...)
417424
418425
# Requests to https://server.com/some/path will have their responses mocked
419426
@@ -488,14 +495,12 @@ Selenium Wire works by redirecting browser traffic through an internal proxy ser
488495
489496
.. _`request interceptor`: #intercepting-requests-and-responses
490497

491-
If you find you're still not getting the performance you want after limiting request capture, you might try switching to the `mitmproxy backend`_.
492-
493-
.. _`mitmproxy backend`: #backends
494-
495498
Proxies
496499
~~~~~~~
497500

498-
If the site you are accessing sits behind a proxy server you can tell Selenium Wire about that proxy server in the options you pass to the webdriver instance. The configuration takes the following format:
501+
If the site you are accessing sits behind a proxy server you can tell Selenium Wire about that proxy server in the options you pass to the webdriver.
502+
503+
The configuration takes the following format:
499504

500505
.. code:: python
501506

0 commit comments

Comments
 (0)