Skip to content

add SELENIUM_EXPERIMENTAL_OPTIONS parameter, to enable to pass extra … #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions scrapy_selenium/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SeleniumMiddleware:
"""Scrapy middleware handling the requests using selenium"""

def __init__(self, driver_name, driver_executable_path,
browser_executable_path, command_executor, driver_arguments):
browser_executable_path, command_executor, driver_arguments, experimental_options, extensions):
"""Initialize the selenium webdriver

Parameters
Expand Down Expand Up @@ -45,6 +45,10 @@ def __init__(self, driver_name, driver_executable_path,
driver_options.binary_location = browser_executable_path
for argument in driver_arguments:
driver_options.add_argument(argument)
for option, value in experimental_options.items():
driver_options.add_experimental_option(option, value)
for extension in extensions:
driver_options.add_extension(extension)

driver_kwargs = {
'executable_path': driver_executable_path,
Expand Down Expand Up @@ -74,6 +78,8 @@ def from_crawler(cls, crawler):
browser_executable_path = crawler.settings.get('SELENIUM_BROWSER_EXECUTABLE_PATH')
command_executor = crawler.settings.get('SELENIUM_COMMAND_EXECUTOR')
driver_arguments = crawler.settings.get('SELENIUM_DRIVER_ARGUMENTS')
driver_experimental_options = crawler.settings.get('SELENIUM_EXPERIMENTAL_OPTIONS', {})
driver_extensions = crawler.settings.get('SELENIUM_EXTENSIONS', [])

if driver_name is None:
raise NotConfigured('SELENIUM_DRIVER_NAME must be set')
Expand All @@ -87,7 +93,9 @@ def from_crawler(cls, crawler):
driver_executable_path=driver_executable_path,
browser_executable_path=browser_executable_path,
command_executor=command_executor,
driver_arguments=driver_arguments
driver_arguments=driver_arguments,
experimental_options=driver_experimental_options,
extensions=driver_extensions
)

crawler.signals.connect(middleware.spider_closed, signals.spider_closed)
Expand Down