def create_browser(): driver_type = os.getenv('WEBDRIVER', 'chrome').lower() headless = os.getenv('HEADLESS', 'True') == 'True' if driver_type == 'chrome': chromedriver_binary.add_chromedriver_to_path() os.chmod(chromedriver_binary.chromedriver_filename, 0o755) chrome_options = webdriver.ChromeOptions() chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-dev-shm-usage") return Browser(driver_type, headless=headless, options=chrome_options) return Browser(driver_type, headless=headless)
def main(driver): # go cluster driver.get('https://cluster.mu/') # login login(driver) # login後は待った方が良さげ time.sleep(10) # photo list driver.get('https://cluster.mu/account/photos') # DL list dl_list = get_dl_list(driver) for url in tqdm(dl_list): download_img(url) time.sleep(1) if __name__ == '__main__': chromedriver_binary.add_chromedriver_to_path() driver = webdriver.Chrome() driver.implicitly_wait(5) main(driver) driver.quit()
def create_browser(): chromedriver_binary.add_chromedriver_to_path() chrome_options = webdriver.ChromeOptions() chrome_options.add_argument("--no-sandbox") chrome_options.headless = bool(strtobool(os.getenv('HEADLESS', 'True'))) return webdriver.Chrome(chrome_options=chrome_options)
def __init__(self): add_chromedriver_to_path() self.driver = webdriver.Chrome()
def _instantiate_chromedriver(ctx: Context) -> None: """Attempt to start the chromedriver, retrying if there are connection errors. Args: ctx: The behave context object. Raises: :py:class:`.ConnectionResetError`: If starting chromedriver fails too many times. """ # Set the selenium logs to warning only LOG.setLevel(logging.WARNING) chrome_options = webdriver.ChromeOptions() # Prevent images from loading (should decrease load times) prefs = {"profile.managed_default_content_settings.images": 1} chrome_options.add_experimental_option("prefs", prefs) chrome_options.add_argument("--no-sandbox") # Ignore CORS errors chrome_options.add_argument("--disable-web-security") # set logging capability chrome_options.set_capability("loggingPrefs", {"browser": "ALL"}) # if ctx.zap_proxy_url: # chrome_options.add_argument(f"--proxy-server={ctx.zap_proxy_url}") chrome_options.add_argument("--window-size=1920,1080") # Attempt the connection... Max attempts 3 attempts_remaining = 3 while attempts_remaining > 0: try: LOGGER.info("Instantiating chromedriver...") # use the chromedriver binary loader. this forces the location on path chromedriver_binary.add_chromedriver_to_path() ctx.driver = webdriver.Chrome(chrome_options=chrome_options) LOGGER.debug( f"Chromedriver running from {chromedriver_binary.chromedriver_filename}" ) LOGGER.info("Connected to chromedriver successfully!") break except (ConnectionResetError, ProtocolError): # one attempt used... attempts_remaining -= 1 LOGGER.warning( "Connection was refused, will try again {} more " "time{}".format( attempts_remaining, "" if attempts_remaining == 1 else "s" ) ) # sleep 3 seconds between attempts time.sleep(3) else: raise ConnectionResetError( "Failed connecting to chromedriver after exhausting all 3 attempts. Giving up!" ) # Set the latency for the browser if not defaulted to 0 latency = ctx.latency if latency != "None": LOGGER.debug(f"Non default latency was detected as: {latency}") _set_browser_latency(ctx, latency)