Exemple #1
0
def build_options(browser, browser_options: List[str],
                  experimental_options: Optional[List[dict]],
                  extension_paths: Optional[List[str]]):
    """ Build the Options object for Chrome or Firefox.

    Args:
        browser: The name of the browser.
        browser_options: The list of options/arguments to include.
        experimental_options: The list of experimental options to include.
        extension_paths: The list of extensions to add to the browser session.

    Examples:
        WebDriverFactory().build_options('chrome', ['headless', 'incognito'], [{'useAutomationExtension', False}])
    """
    browser = browser.lower()
    if browser == Browser.CHROME:
        options = webdriver.ChromeOptions()
    elif browser == Browser.FIREFOX:
        options = webdriver.FirefoxOptions()
    elif browser == Browser.IE:
        options = webdriver.IeOptions()
    elif browser == Browser.OPERA:
        options = webdriver.ChromeOptions()
    elif browser == Browser.EDGE:
        options = Options()
    else:
        raise ValueError(
            f'{browser} is not supported. https://elsnoman.gitbook.io/pylenium/configuration/driver'
        )

    for option in browser_options:
        if option.startswith('--'):
            options.add_argument(option)
        else:
            options.add_argument(f'--{option}')

    if experimental_options:
        for exp_option in experimental_options:
            (name, value), = exp_option.items()
            options.add_experimental_option(name, value)

    if extension_paths:
        for path in extension_paths:
            options.add_extension(path)

    return options
Exemple #2
0
def open_browser(executable_path="msedgedriver",
                 edge_args=None,
                 desired_capabilities=None,
                 **kwargs):
    """Open Edge browser instance and cache the driver.

    Parameters
    ----------
    executable_path : str (Default "msedgedriver")
        path to the executable. If the default is used it assumes the
        executable is in the $PATH.
    port : int (Default 0)
        port you would like the service to run, if left as 0, a free port will
        be found.
    desired_capabilities : dict (Default None)
        Dictionary object with non-browser specific capabilities only, such as
        "proxy" or "loggingPref".
    chrome_args : Optional arguments to modify browser settings
    """
    options = Options()
    options.use_chromium = True

    # Gets rid of Devtools listening .... printing
    # other non-sensical error messages
    options.add_experimental_option('excludeSwitches', ['enable-logging'])

    if platform.system().lower() == "windows":
        options.set_capability("platform", "WINDOWS")

    if platform.system().lower() == "linux":
        options.set_capability("platform", "LINUX")

    if platform.system().lower() == "darwin":
        options.set_capability("platform", "MAC")

    # If user wants to re-use existing browser session then
    # he/she has to set variable BROWSER_REUSE_ENABLED to True.
    # If enabled, then web driver connection details are written
    # to an argument file. This file enables re-use of the current
    # chrome session.
    #
    # When variables BROWSER_SESSION_ID and BROWSER_EXECUTOR_URL are
    # set from argument file, then OpenBrowser will use those
    # parameters instead of opening new chrome session.
    # New Remote Web Driver is created in headless mode.
    edge_path = kwargs.get(
        'edge_path', None) or BuiltIn().get_variable_value('${EDGE_PATH}')
    if edge_path:
        options.binary_location = edge_path

    if user.is_root() or user.is_docker():
        options.add_argument("no-sandbox")
    if edge_args:
        if any('--headless' in _.lower() for _ in edge_args):
            CONFIG.set_value('Headless', True)
        for item in edge_args:
            options.add_argument(item.lstrip())
    options.add_argument("start-maximized")
    options.add_argument("--disable-notifications")
    if 'headless' in kwargs:
        CONFIG.set_value('Headless', True)
        options.add_argument("--headless")
    if 'prefs' in kwargs:
        if isinstance(kwargs.get('prefs'), dict):
            prefs = kwargs.get('prefs')
        else:
            prefs = util.prefs_to_dict(kwargs.get('prefs').strip())
        options.add_experimental_option('prefs', prefs)
        logger.warn("prefs: {}".format(prefs))
    driver = Edge(BuiltIn().get_variable_value('${EDGEDRIVER_PATH}')
                  or executable_path,
                  options=options,
                  capabilities=desired_capabilities)
    browser.cache_browser(driver)
    return driver
Exemple #3
0
import time
from selenium import webdriver
from selenium.webdriver.common import service
from selenium.webdriver.edge.service import Service
from selenium.webdriver.edge.options import Options
from bs4 import BeautifulSoup
import xlsxwriter

edge_options = Options()
edge_service = Service("C:\Program Files (x86)\Microsoft\Edge\Application\msedgedriver.exe")
edge_options.add_argument("headless")
driver = webdriver.Edge(service=edge_service)
driver.get("https://store.steampowered.com/search/?sort_by=_ASC&ignore_preferences=1&filter=topsellers")
time.sleep(2)
scroll_pause_time = 1
screen_height = driver.execute_script("return window.screen.height;")
i = 1

workbook = xlsxwriter.Workbook('SteamGames.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold':True})

worksheet.write('A1', 'Name', bold)
worksheet.write('B1', 'Price', bold)
worksheet.write('C1', 'Release Date', bold)
worksheet.write('D1', 'Publisher', bold)
worksheet.write('E1', 'Developer', bold)
worksheet.write('F1', '% Positive Reviews (30 days)', bold)
worksheet.write('G1', 'Total Number Reviews (30 days)', bold)
worksheet.write('H1', '% Positive Reviews (All Time)', bold)
worksheet.write('I1', 'Total Number Reviews (All Time)', bold)
Exemple #4
0
URL = "http://orteil.dashnet.org/experiments/cookie/"

STORE_ITEMS = [
    "buyCursor",
    "buyGrandma",
    "buyFactory",
    "buyMine",
    "buyShipment",
    "buyAlchemy lab",
    "buyPortal",
    "buyTime machine",
]
store = []

options = Options()
options.add_argument("window-size=1920,1080")

driver = webdriver.Edge(options=options)
driver.get(URL)

cps = driver.find_element(By.ID, "cps")
money = driver.find_element(By.ID, "money")
cookie = driver.find_element(By.ID, "cookie")

begin = before = now = time.time()

while now - begin < 120:

    while now - before < 5:

        cookie.click()