Skip to main content

Extends Selenium WebDriver classes to include the request function from the Requests library, while doing all the needed cookie and request headers handling.

Project description

Selenium Requests

Extends Selenium WebDriver classes to include the request function from the Requests library, while doing all the needed cookie and request headers handling.

Before the actual request is made, a local HTTP server is started that serves a single request made by the webdriver instance to get the "standard" HTTP request headers sent by this webdriver; these are cached (only happens once during its lifetime) and later used in conjunction with the Requests library to make the requests look identical to those that would have been sent by the webdriver. Cookies held by the webdriver instance are added to the request headers and those returned in a response automatically set for the webdriver instance.

Features

  • Determines and sends the default HTTP headers (User-Agent etc.) for the chosen WebDriver
  • Manages cookies bidirectionally between requests and Selenium
  • Switches to already existing window handles or temporarily creates them to work with the webdriver's cookies when making a request
  • All operations preserve the original state of the WebDriver (active window handle and window handles)
  • Tested to work with Selenium (3.0.1) using Mozilla Firefox (49.0.2), Google Chrome (54.0.2840.71) and PhantomJS (2.1.1)

Usage

# Import any WebDriver class that you would usually import from
# selenium.webdriver from the seleniumrequests module
from seleniumrequests import Firefox

# Simple usage with built-in WebDrivers:
webdriver = Firefox()
response = webdriver.request('GET', 'https://www.google.com/')
print(response)


# More complex usage, using a WebDriver from another Selenium-related module:
from seleniumrequests.request import RequestsSessionMixin
from someothermodule import CustomWebDriver


class MyCustomWebDriver(RequestsSessionMixin, CustomWebDriver):
    pass


custom_webdriver = MyCustomWebDriver()
response = custom_webdriver.request('GET', 'https://www.google.com/')
print(response)

Installation

pip install selenium-requests

Remote WebDriver

When using webdriver.Remote it is very likely that the HTTP proxy server spawned by selenium-requests does not run on the same machine. By default, the webdriver tries to access the proxy server under 127.0.0.1. This can be changed by passing the proxy_host= argument with the correct IP or hostname to the webdriver.

driver = seleniumrequests.Remote(
    'http://192.168.101.1:4444/wd/hub',
    options=chrome_options,
    proxy_host='192.168.101.2'
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

selenium-requests-1.3.4.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

selenium_requests-1.3.4-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file selenium-requests-1.3.4.tar.gz.

File metadata

  • Download URL: selenium-requests-1.3.4.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.2 Linux/5.16.8-arch1-1

File hashes

Hashes for selenium-requests-1.3.4.tar.gz
Algorithm Hash digest
SHA256 8eb1aff3ccc71b2841db1e6d28d9715c9bcab406773ca3a28a48d4e8114098bb
MD5 c6ec70ea7982588dbbc32a0c1f531fee
BLAKE2b-256 350506be5e15cdafb29f839f266996113c6519e63dcc655359457318c3468702

See more details on using hashes here.

File details

Details for the file selenium_requests-1.3.4-py3-none-any.whl.

File metadata

  • Download URL: selenium_requests-1.3.4-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.2 Linux/5.16.8-arch1-1

File hashes

Hashes for selenium_requests-1.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 62e2f444b0afcb4d0c6a7df17c1035191a8200f83b59bcb8922925940d131526
MD5 275f5489d593b249c9144f4a74c6d1d6
BLAKE2b-256 16e23bfdaf33a53e6a314612d31e5ac514a614ac178761c8f2cb87ee61523a59

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page