
Selenium के Python बाइंडिंग्स का विस्तार करता है, जिससे आपको ब्राउज़र द्वारा किए गए अनुरोधों का निरीक्षण करने की क्षमता मिलती है।
Selenium Wire अब अनुरक्षित नहीं किया जा रहा है। आपके समर्थन और सभी योगदानों के लिए धन्यवाद।
Selenium Wire, Selenium के <https://www.selenium.dev/documentation/en/>_ Python बाइंडिंग्स को विस्तारित करता है ताकि आपको ब्राउज़र द्वारा किए गए अंतर्निहित अनुरोधों तक पहुंच मिल सके। आप अपना कोड उसी तरह लिखते हैं जैसे आप Selenium के साथ लिखते हैं, लेकिन आपको अनुरोधों और प्रतिक्रियाओं का निरीक्षण करने और उन्हें तुरंत बदलने के लिए अतिरिक्त APIs मिलती हैं।
.. image:: https://github.com/wkeeling/selenium-wire/workflows/build/badge.svg :target: https://github.com/wkeeling/selenium-wire/actions
.. image:: https://codecov.io/gh/wkeeling/selenium-wire/branch/master/graph/badge.svg :target: https://codecov.io/gh/wkeeling/selenium-wire
.. image:: https://img.shields.io/badge/python-3.7%2C%203.8%2C%203.9%2C%203.10-blue.svg :target: https://pypi.python.org/pypi/selenium-wire
.. image:: https://img.shields.io/pypi/v/selenium-wire.svg :target: https://pypi.python.org/pypi/selenium-wire
.. image:: https://img.shields.io/pypi/l/selenium-wire.svg :target: https://pypi.python.org/pypi/selenium-wire
.. image:: https://pepy.tech/badge/selenium-wire/month :target: https://pepy.tech/project/selenium-wire
सरल उदाहरण~~~~~~~~~~~~~~
.. code:: python
from seleniumwire import webdriver # Import from seleniumwire
# Create a new instance of the Chrome driver
driver = webdriver.Chrome()
# Go to the Google home page
driver.get('https://www.google.com')
# Access requests via the `requests` attribute
for request in driver.requests:
if request.response:
print(
request.url,
request.response.status_code,
request.response.headers['Content-Type']
)
Prints:
.. code:: bash
https://www.google.com/ 200 text/html; charset=UTF-8
https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png 200 image/png
https://consent.google.com/status?continue=https://www.google.com&pc=s×tamp=1531511954&gl=GB 204 text/html; charset=utf-8
https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png 200 image/png
https://ssl.gstatic.com/gb/images/i2_2ec824b0.png 200 image/png
https://www.google.com/gen_204?s=webaft&t=aft&atyp=csi&ei=kgRJW7DBONKTlwTK77wQ&rt=wsrt.366,aft.58,prt.58 204 text/html; charset=UTF-8
...
Features
* Pure Python, user-friendly API
* HTTP and HTTPS requests captured
* Intercept requests and responses
* Modify headers, parameters, body content on the fly
* Capture websocket messages
* HAR format supported
* Proxy server support
Compatibilty
Table of Contents
- `स्थापना`_
* `ब्राउज़र सेटअप`_
* `OpenSSL`_
- `वेबड्राइवर बनाना`_
- `अनुरोधों तक पहुँचना`_
- `अनुरोध ऑब्जेक्ट`_
- `प्रतिक्रिया ऑब्जेक्ट`_
- `अनुरोधों और प्रतिक्रियाओं को इंटरसेप्ट करना`_
* `उदाहरण: अनुरोध हेडर जोड़ें`_
* `उदाहरण: मौजूदा अनुरोध हेडर बदलें`_
* `उदाहरण: प्रतिक्रिया हेडर जोड़ें`_
* `उदाहरण: अनुरोध पैरामीटर जोड़ें`_
* `उदाहरण: POST अनुरोध बॉडी में JSON अपडेट करें`_
* `उदाहरण: बेसिक प्रमाणीकरण`_
* `उदाहरण: अनुरोध ब्लॉक करें`_
* `उदाहरण: प्रतिक्रिया मॉक करें`_
* `इंटरसेप्टर अनसेट करें`_
- `अनुरोध कैप्चर सीमित करना`_
- `अनुरोध भंडारण`_
* `इन-मेमोरी भंडारण`_
- `प्रॉक्सी`_
* `SOCKS`_
* `गतिशील रूप से स्विच करना`_
- `बॉट पहचान`_
- `प्रमाणपत्र`_
* `अपना स्वयं का प्रमाणपत्र उपयोग करना`_
- `सभी विकल्प`_
- `लाइसेंस`_
स्थापना~~~~~~~~~~~~
Install using pip:
.. code:: bash
pip install selenium-wire
If you get an error about not being able to build cryptography you may be running an old version of pip. Try upgrading pip with ``python -m pip install --upgrade pip`` and then re-run the above command.
Browser Setup
-------------
No specific configuration should be necessary except to ensure that you have downloaded the relevent webdriver executable for your browser and placed it somewhere on your system PATH.
- `Download <https://sites.google.com/chromium.org/driver/>`__ webdriver for Chrome
- `Download <https://github.com/mozilla/geckodriver/>`__ webdriver for Firefox
- `Download <https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/>`__ webdriver for Edge
OpenSSL
-------
Selenium Wire requires OpenSSL for decrypting HTTPS requests. This is probably already installed on your system (you can check by running ``openssl version`` on the command line). If it's not installed you can install it with:
**Linux**
.. code:: bash
# For apt based Linux systems
sudo apt install openssl
# For RPM based Linux systems
sudo yum install openssl
# For Linux alpine
sudo apk add openssl
**MacOS**
.. code:: bash
brew install openssl
**Windows**
No installation is required.
Creating the Webdriver
सुनिश्चित करें कि आप webdriver को seleniumwire पैकेज से आयात करते हैं:
.. code:: python
from seleniumwire import webdriver
फिर webdriver को उसी तरह इंस्टैंशिएट करें जैसे आप Selenium का सीधे उपयोग कर रहे हों। आप कोई भी वांछित क्षमताएँ या ब्राउज़र-विशिष्ट विकल्प पास कर सकते हैं - जैसे निष्पादन योग्य पथ, हेडलेस मोड आदि। Selenium Wire के पास भी अपने विकल्प_ हैं जिन्हें seleniumwire_options विशेषता में पास किया जा सकता है।
.. code:: python
# Create the driver with no options (use defaults)
driver = webdriver.Chrome()
# Or create using browser specific options and/or seleniumwire_options options
driver = webdriver.Chrome(
options = webdriver.ChromeOptions(...),
seleniumwire_options={...}
)
.. _अपने विकल्प: #all-options
ध्यान दें कि webdriver के उप-पैकेजों के लिए, आपको इन्हें सीधे selenium से आयात करना जारी रखना चाहिए। उदाहरण के लिए, WebDriverWait आयात करने के लिए:
.. code:: python
# Sub-packages of webdriver must still be imported from `selenium` itself
from selenium.webdriver.support.ui import WebDriverWait
रिमोट Webdriver
Selenium Wire के पास रिमोट webdriver क्लाइंट का उपयोग करने के लिए सीमित समर्थन है। जब आप रिमोट webdriver का एक उदाहरण बनाते हैं, तो आपको Selenium Wire चलाने वाली मशीन (या कंटेनर) का होस्टनाम या IP पता निर्दिष्ट करना होगा। यह रिमोट उदाहरण को अपने अनुरोधों और प्रतिक्रियाओं के साथ Selenium Wire को वापस संचार करने की अनुमति देता है।
.. code:: python
options = {
'addr': 'hostname_or_ip' # Address of the machine running Selenium Wire. Explicitly use 127.0.0.1 rather than localhost if remote session is running locally.
}
driver = webdriver.Remote(
command_executor='http://www.example.com',
seleniumwire_options=options
)
यदि ब्राउज़र चलाने वाली मशीन को Selenium Wire चलाने वाली मशीन से बात करने के लिए एक अलग पते का उपयोग करने की आवश्यकता है, तो आपको ब्राउज़र को मैन्युअल रूप से कॉन्फ़िगर करना होगा। यह मुद्दा <https://github.com/wkeeling/selenium-wire/issues/220>_ अधिक विस्तार में जाता है।
अनुरोधों तक पहुँचना~~~~~~~~~~~~~~~~~~
Selenium Wire captures all HTTP/HTTPS traffic made by the browser [1]_. The following attributes provide access to requests and responses.
driver.requests
The list of captured requests in chronological order.
driver.last_request
Convenience attribute for retrieving the most recently captured request. This is more efficient than using driver.requests[-1].