allow configuration of additional browser extensions

This commit is contained in:
sebthom
2022-02-17 13:08:09 +01:00
parent b879e3d6db
commit 7ee2d533df
4 changed files with 24 additions and 10 deletions

View File

@@ -212,8 +212,8 @@ ad_defaults:
active: true active: true
type: # one of: OFFER, WANTED type: # one of: OFFER, WANTED
description: description:
prefix: prefix: ""
suffix: suffix: ""
price_type: # one of: FIXED, NEGOTIABLE, GIVE_AWAY price_type: # one of: FIXED, NEGOTIABLE, GIVE_AWAY
shipping_type: # one of: PICKUP, SHIPPING, NOT_APPLICABLE shipping_type: # one of: PICKUP, SHIPPING, NOT_APPLICABLE
contact: contact:
@@ -239,11 +239,12 @@ browser:
# --headless # --headless
# --start-maximized # --start-maximized
binary_location: # path to custom browser executable, if not specified will be looked up on PATH binary_location: # path to custom browser executable, if not specified will be looked up on PATH
extensions: [] # a list of .crx extension files to be loaded
# login credentials # login credentials
login: login:
username: username: ""
password: password: ""
``` ```

View File

@@ -272,6 +272,7 @@ class KleinanzeigenBot(SeleniumMixin):
self.browser_arguments = self.config["browser"]["arguments"] self.browser_arguments = self.config["browser"]["arguments"]
self.browser_binary_location = self.config["browser"]["binary_location"] self.browser_binary_location = self.config["browser"]["binary_location"]
self.browser_extensions = [ abspath(item, relative_to = self.config_file_path) for item in self.config["browser"]["extensions"] ]
def login(self) -> None: def login(self) -> None:
LOG.info("Logging in as [%s]...", self.config["login"]["username"]) LOG.info("Logging in as [%s]...", self.config["login"]["username"])

View File

@@ -3,23 +3,27 @@ ad_files:
- "**/ad_*.yml" - "**/ad_*.yml"
- "**/ad_*.yaml" - "**/ad_*.yaml"
# default values for ads, can be overwritten in each ad configuration file
ad_defaults: ad_defaults:
active: true active: true
type: OFFER type: OFFER # one of: OFFER, WANTED
description: description:
prefix: "" prefix: ""
suffix: "" suffix: ""
price_type: NEGOTIABLE price_type: NEGOTIABLE # one of: FIXED, NEGOTIABLE, GIVE_AWAY
shipping_type: SHIPPING shipping_type: SHIPPING # one of: PICKUP, SHIPPING, NOT_APPLICABLE
contact: contact:
name: "" name: ""
street: "" street: ""
zipcode: zipcode:
phone: "" # IMPORTANT: surround phone number with quotes to prevent removal of leading zeros phone: "" # IMPORTANT: surround phone number with quotes to prevent removal of leading zeros
republication_interval: 7 republication_interval: 7 # every X days ads should be re-published
# additional name to category ID mappings, see default list at
# https://github.com/Second-Hand-Friends/kleinanzeigen-bot/blob/main/kleinanzeigen_bot/resources/categories.yaml
categories: [] categories: []
# browser configuration
browser: browser:
# https://peter.sh/experiments/chromium-command-line-switches/ # https://peter.sh/experiments/chromium-command-line-switches/
arguments: arguments:
@@ -28,8 +32,10 @@ browser:
- --no-sandbox - --no-sandbox
# --headless # --headless
# --start-maximized # --start-maximized
binary_location: binary_location: # path to custom browser executable, if not specified will be looked up on PATH
extensions: [] # a list of .crx extension files to be loaded
# login credentials
login: login:
username: "" username: ""
password: "" password: ""

View File

@@ -35,6 +35,7 @@ class SeleniumMixin:
def __init__(self): def __init__(self):
self.browser_arguments:Iterable[str] = [] self.browser_arguments:Iterable[str] = []
self.browser_binary_location:str = None self.browser_binary_location:str = None
self.browser_extensions:Iterable[str] = []
self.webdriver:WebDriver = None self.webdriver:WebDriver = None
def create_webdriver_session(self) -> None: def create_webdriver_session(self) -> None:
@@ -54,6 +55,11 @@ class SeleniumMixin:
browser_options.add_argument(chrome_option) browser_options.add_argument(chrome_option)
LOG.debug("Effective browser arguments: %s", browser_options.arguments) LOG.debug("Effective browser arguments: %s", browser_options.arguments)
for crx_extension in self.browser_extensions:
ensure(os.path.exists(crx_extension), f"Configured extension-file [{crx_extension}] does not exist.")
browser_options.add_extension(crx_extension)
LOG.debug("Effective browser extensions: %s", browser_options.extensions)
browser_options.add_experimental_option("excludeSwitches", ["enable-automation"]) browser_options.add_experimental_option("excludeSwitches", ["enable-automation"])
browser_options.add_experimental_option("useAutomationExtension", False) browser_options.add_experimental_option("useAutomationExtension", False)
browser_options.add_experimental_option("prefs", { browser_options.add_experimental_option("prefs", {