Example #1
0
def main():
    
    geckodriver_autoinstaller.install()
    
    driver = webdriver.Firefox()
    URL = 'https://steamtime.info/'
    
    driver.get(URL)
    
    # Used to ensure all conditions are met (cookies accepted, table size set to 100 and html converted to a string)
    overall_control = False
    
    cookie_control = click_cookie(driver)
    
    dropdown_control = set_dropdown(driver)
    
    table_element = select_table(driver)
    
    if((cookie_control== True) and (dropdown_control == True) and (len(table_element) > 1)):
       overall_control = True
       
    # Recursive call to main to ensure all controls are met
    while(overall_control != True):
        driver.close()
        main()
    
    list_of_id_nums = parse_info(table_element)
    
    write_to_file(list_of_id_nums)
    
    # Output array of steam id nums
    print(list_of_id_nums)
    print(len(list_of_id_nums))
Example #2
0
def firefox_driver(args):
    """Start firefox."""
    import geckodriver_autoinstaller

    geckodriver_autoinstaller.install()

    outdir = os.path.abspath(args["--out"])
    os.makedirs(Path(outdir), exist_ok=True)

    profile = webdriver.FirefoxProfile()
    profile.set_preference("browser.download.folderList", 2)
    profile.set_preference("browser.download.manager.showWhenStarting", False)
    profile.set_preference("browser.download.dir", outdir)
    profile.set_preference("browser.download.lastDir", args["--out"])
    profile.set_preference(
        "browser.helperApps.neverAsk.saveToDisk",
        "image/png, image/svg+xml, text/csv, text/plain, application/json",
    )

    options = Options()
    options.headless = not args["--interactive"]
    display = Display(visible=0, size=(800, 600))
    display.start()
    driver = webdriver.Firefox(
        options=options,
        firefox_profile=profile,
        service_log_path=args["--driver-log"],
    )
    time.sleep(2)
    return driver, display
Example #3
0
    def __init__(self, username: str, password: str, is_windows: bool = False):
        self.username = username
        self.password = password
        self.login_url = "https://zhambyltipo.kz/kk/site/login"

        if is_windows:
            geckodriver_autoinstaller.install()
Example #4
0
def webdriver_generate():
    geckodriver_autoinstaller.install()
    profile = webdriver.FirefoxProfile()
    options = Options()
    options.headless = True
    profile.set_preference("media.volume_scale", "0.0")
    return webdriver.Firefox(firefox_profile=profile, options=options)
Example #5
0
def autoAdd(email, password, num):
    geckodriver_autoinstaller.install()
    driver = webdriver.Firefox()
    driver.get("https://www.facebook.com/")

    driver.find_element_by_name("email").send_keys(email)
    driver.find_element_by_name("pass").send_keys(password)
    button = driver.find_element_by_name("login")
    button.click()
    sleep(3)

    # search = browser.find_element_by_xpath('.//[@type="search"]')
    search = driver.find_element_by_css_selector('input[type="search" i]')
    search.click()

    sleep(3)
    p = driver.find_element_by_xpath(
        '/html/body/div[1]/div/div[1]/div/div[2]/div[2]/div/div[2]/div/ul/li[1]/div/a'
    )
    p.click()

    sleep(3)
    for i in range(num):

        driver.find_element_by_css_selector(
            'div.rwwkvi1h:nth-child(1)').click()
        sleep(2)
Example #6
0
    def search_genius(self, search):
        options = Options()
        options.add_argument('-headless')
        geckodriver_autoinstaller.install()
        __driver = webdriver.Firefox(options=options)
        __URL = "https://genius.com/search?q="
        __Final_URL = __URL + search.strip().replace(" ", "%20")
        __driver.get(__Final_URL)
        try:
            #wait until the page is fully loaded and the mini card is ready
            __element_present = EC.presence_of_element_located((By.CLASS_NAME, "mini_card"))
            WebDriverWait(__driver, 5).until(__element_present)   
        except TimeoutException:
            raise SongNotFoundError("Song not found or input error")

        __mini_cards = __driver.find_elements_by_class_name("mini_card")
        try:
            self.URL = __mini_cards[1].get_attribute("href")
        except IndexError:
            __driver.quit()
            raise SongNotFoundError("Song not found or input error")
        # __driver.quit()
        __driver.close()
        __session = requests.Session()
        __request = __session.get(self.URL)
        __soup = BeautifulSoup(__request.content, 'html.parser')
        __page = __soup.find(class_="lyrics")
        self.lyrics = __page.text
        __page = __soup.find(class_="header_with_cover_art-primary_info-title")
        self.title = __page.text
Example #7
0
def start_selenium_driver(desired_caps,
                          url=None,
                          debug=None,
                          browser=None,
                          chrome_options=None,
                          firefox_options=None) -> WebDriver:
    options = chrome_options
    if firefox_options is not None:
        options = firefox_options

    if options is not None:
        logger.log("setting options: " + options.to_capabilities().__str__())

    logger.log("setting capabilities: " + desired_caps.__str__())
    logger.log(f"starting selenium {browser.lower()} driver...")
    err = None
    for x in range(2):
        try:
            if url is not None:
                logger.log(f"selenium running on {url}. \n")
                driver = webdriver.Remote(url, desired_caps, options=options)
            else:
                if browser.lower() == 'chrome':
                    driver = webdriver.Chrome(
                        desired_capabilities=desired_caps, options=options)
                elif browser.lower() == 'firefox':
                    import geckodriver_autoinstaller
                    try:
                        geckodriver_autoinstaller.install()
                    except Exception as error:
                        logger.log_warn("Could not retrieve geckodriver: " +
                                        error.__str__())
                    if "marionette" not in desired_caps:
                        desired_caps["marionette"] = True
                    driver = webdriver.Firefox(
                        firefox_options=options,
                        desired_capabilities=desired_caps)
                elif browser.lower() == 'safari':
                    driver = webdriver.Safari(
                        desired_capabilities=desired_caps)
                elif browser.lower() == 'edge':
                    driver = webdriver.Edge(capabilities=desired_caps)
                elif browser.lower() == 'ie':
                    driver = webdriver.Ie(capabilities=desired_caps)
                elif browser.lower() == 'opera':
                    driver = webdriver.Opera(desired_capabilities=desired_caps)
                elif browser.lower() == 'phantomjs':
                    driver = webdriver.PhantomJS(
                        desired_capabilities=desired_caps)
                else:
                    raise Exception(
                        f"Invalid browser '{browser}'. Please choose one from: chrome,firefox,safari,edge,"
                        f"ie,opera,phantomjs")
            atexit.register(__quit_driver, driver, debug)
            return driver
        except Exception as error:
            err = error

    raise err
Example #8
0
def run(browser: str="", mute_browser: bool=True, headless: bool=True) -> webdriver:
    # Search for browsers
    system = platform.system()
    browsers = {
        "firefox": 0,
        "chrome": 0,
        "edge": 0,
    }
    webdrivers = {
        "geckodriver": 0,
        "chromedriver": 0,
    }
    if browser == "firefox":
        browsers['firefox'] = 1
    elif browser == "chrome":
        browsers["chrome"] = 1
    else:
        if system == "Linux":
            from distutils.spawn import find_executable
            if find_executable("firefox"):
                if find_executable('geckodriver'):
                    webdrivers['geckodriver'] = 1
                browsers["firefox"] = 1
            if find_executable("chromium"):
                if find_executable('chromedriver'):
                    webdrivers['chromedriver'] = 1
                browsers["chrome"] = 1
        elif system == "Windows":
            import os
            if os.path.isdir("C:\\Program Files\\Google\\Chrome"):
                browsers["chrome"] = 1
            if os.path.isdir("C:\\Program Files (x86)\\Google\\Chrome"):
                browsers["chrome"] = 1
            if os.path.isdir("C:\\Program Files\\Mozilla Firefox"):
                browsers["firefox"] = 1
            if os.path.isdir("C:\\Program Files (x86)\\Mozilla Firefox"):
                browsers["firefox"] = 1
        
    
    if browsers["chrome"] == 1:
        if not webdrivers['chromedriver'] == 1:
            import chromedriver_autoinstaller
            chromedriver_autoinstaller.install()
        options = webdriver.ChromeOptions()
        if headless:
            options.headless = True
        if mute_browser:
            options.add_argument("--mute-audio")
        return webdriver.Chrome(chrome_options=options)
    elif browsers["firefox"] == 1:
        if not webdrivers['geckodriver'] == 1:
            import geckodriver_autoinstaller
            geckodriver_autoinstaller.install()
        options = webdriver.FirefoxProfile()
        if headless:
            options.headless = True
        if mute_browser:
            options.set_preference("media.volume_scale", "0.0")
        return webdriver.Firefox(firefox_profile=options)
Example #9
0
 def __init__(self, username, password):
     geckodriver_autoinstaller.install()
     self.options = Options()
     self.options.headless = True
     self.options.add_argument("--window-size=1366x768")
     self.driver = webdriver.Firefox(options=self.options)
     self.username = username
     self.password = password
 def __init__(self, title, graph, coords, export_path):
     self.title = title
     self.width, self.height = 800, 532
     self.graph = graph
     self.coords = coords
     self.export_path = export_path
     self.plot = self.create_plot()
     chromedriver_autoinstaller.install(cwd=True)
     geckodriver_autoinstaller.install(cwd=True)
 def setUpClass(cls):
     super().setUpClass()
     geckodriver_autoinstaller.install()  # Check if the current version of geckodriver exists
                                         # and if it doesn't exist, download it automatically,
                                         # then add geckodriver to path
     cls.browser = cls.get_browser_mode()
     cls.browser.delete_all_cookies()
     cls.browser.set_window_position(0, 0)
     # weird size is so I can get the entire web page video recorded without scrolling
     cls.browser.set_window_size(2100, 1181)
Example #12
0
 def __init__(self,
              use_virtual_display: Optional[bool] = False,
              viewport_width: Optional[int] = 1500,
              viewport_height: Optional[int] = 3000):
     geckodriver_autoinstaller.install()
     self.use_virtual_display = use_virtual_display
     self.vdisplay = None
     if self.use_virtual_display:
         self.setup_virtual_display()
     self.driver = webdriver.Firefox()
     # self.driver.maximize_window()
     self.driver.set_window_size(1500, 3000)
Example #13
0
 def _init_firefox(self):
     import selenium.webdriver
     try:
         # Use geckodriver_autoinstaller package if available
         import geckodriver_autoinstaller
         geckodriver_autoinstaller.install()
     except (ImportError, SyntaxError):
         # Fallback to system chromedriver
         pass
     profile = selenium.webdriver.FirefoxProfile()
     profile.set_preference('devtools.console.stdout.content', True)
     self.driver = selenium.webdriver.Firefox(
         firefox_profile=profile, service_log_path=self._logfile.name)
Example #14
0
 def __init__(self):
     chromedriver_autoinstaller.install(
     )  # Check if the current version of chromedriver exists
     # and if it doesn't exist, download it automatically,
     # then add chromedriver to path
     geckodriver_autoinstaller.install()
     if settings.browser == "chrome":
         self.driver = webdriver.Chrome()
     elif settings.browser == "firefox":
         self.driver = webdriver.Firefox()
     else:
         raise Driver.SeleniumDriverNotFound(
             "{settings.browser} not currently supported")
Example #15
0
def start():
    geckodriver_autoinstaller.install()
    driver = webdriver.Firefox()
    driver.get("https://humanbenchmark.com/tests/typing")

    text_box = driver.find_element_by_class_name("letters")
    letters = text_box.find_elements_by_tag_name("span")

    for letter in letters:
        if letter.text == "":
            text_box.send_keys(Keys.SPACE)
        else:
            text_box.send_keys(letter.text)
Example #16
0
def main():
    geckodriver_autoinstaller.install()

    driver = webdriver.Firefox()
    login(driver)

    try:
        while True:
            msg = get_last_message(driver)
            print(msg)
            input()

    except KeyboardInterrupt:
        pass
Example #17
0
def userChoice():
  geckodriver_autoinstaller.install()
  choice = None
  choice = input("Select an option to choose: ")
  if choice == "1":
    randomEmailSender()
  elif choice == "2":
    personMailSender()
  elif choice == "3":
      sys.exit()
  else:
     print("Insert a valid number...")
     time.sleep(1)
     os.system("clear")
Example #18
0
def init_driver(headless=True, proxy=None, show_images=False, option=None, firefox=False, env=None):
    """ initiate a chromedriver or firefoxdriver instance
        --option : other option to add (str)
    """

    if firefox:
        options = FirefoxOptions()
        driver_path = geckodriver_autoinstaller.install()
    else:
        options = ChromeOptions()
        driver_path = chromedriver_autoinstaller.install()

    if headless is True:
        print("Scraping on headless mode.")
        options.add_argument('--disable-gpu')
        options.headless = True
    else:
        options.headless = False
    options.add_argument('log-level=3')
    if proxy is not None:
        options.add_argument('--proxy-server=%s' % proxy)
        print("using proxy : ", proxy)
    if show_images == False and firefox == False:
        prefs = {"profile.managed_default_content_settings.images": 2}
        options.add_experimental_option("prefs", prefs)
    if option is not None:
        options.add_argument(option)

    if firefox:
        driver = webdriver.Firefox(options=options, executable_path=driver_path)
    else:
        driver = webdriver.Chrome(options=options, executable_path=driver_path)

    driver.set_page_load_timeout(100)
    return driver
Example #19
0
 def __init__(self, input_values: Dict[str, str] = None, use_cache=True):
     inline_try(lambda: geckodriver_autoinstaller.install())
     self.__driver = webdriver.Firefox()
     self.__input_values = input_values
     self.__stats = Stats(str(self.__class__))
     self.__use_cache = use_cache
     self.__last_tree = None
     self.__did_visit = False
Example #20
0
def get_bhavcopy():
    zip_file_location = os.path.dirname(os.path.abspath(__file__))
    date = datetime.today()
    day = date.strftime('%d')
    month = date.strftime('%b')
    year = date.strftime('%Y')
    print(day)
    print(month)
    print(year)
    # Installs geckodriver if not already installed
    geckodriver_autoinstaller.install()

    options = webdriver.FirefoxOptions()
    options.set_headless()
    profile = webdriver.FirefoxProfile()
    profile.set_preference('browser.download.folderList', 2)  # custom location
    profile.set_preference('browser.download.manager.showWhenStarting', False)
    profile.set_preference('browser.download.dir', zip_file_location)
    profile.set_preference('browser.helperApps.neverAsk.saveToDisk',
                           'application/x-zip-compressed')

    driver = webdriver.Firefox(firefox_profile=profile,
                               firefox_options=options)
    driver.get('https://www.bseindia.com/markets/MarketInfo/BhavCopy.aspx')

    day_element = driver.find_element_by_xpath(
        '//*[@id="ContentPlaceHolder1_fdate1"]')
    select_option(day_element, '19')
    month_element = driver.find_element_by_xpath(
        '//*[@id="ContentPlaceHolder1_fmonth1"]')
    select_option(month_element, month)
    year_element = driver.find_element_by_xpath(
        '//*[@id="ContentPlaceHolder1_fyear1"]')
    select_option(year_element, year)
    button_element = driver.find_element_by_xpath(
        '//*[@id="ContentPlaceHolder1_btnSubmit"]')
    button_element.click()
    csv_file_element = driver.find_element_by_xpath(
        '//*[@id="ContentPlaceHolder1_btnHylSearBhav"]')
    csv_file_element.click()  # Clicks the link to download csv file
    driver.close()
    open_zip_files(zip_file_location)
    bhavcopy_dict = convert_bhavcopy_to_json(zip_file_location)
    return bhavcopy_dict
Example #21
0
    def __init__(self,
                 use_virtual_display: Optional[bool] = False,
                 viewport_width: Optional[int] = 1500,
                 viewport_height: Optional[int] = 3000):
        print('Initialising Webdriver...')
        geckodriver_autoinstaller.install()
        self.use_virtual_display = use_virtual_display
        self.vdisplay = None

        # Open Browser
        if self.use_virtual_display:
            self.setup_virtual_display(viewport_width=viewport_width,
                                       viewport_height=viewport_height)
        self.driver = webdriver.Firefox()
        self.driver.set_window_size(viewport_width, viewport_height)
        self.viewport_width = self.driver.execute_script(
            'return window.innerWidth;')
        self.viewport_height = self.driver.execute_script(
            'return window.innerHeight;')
def main():
    
    geckodriver_autoinstaller.install()
    
    driver = webdriver.Firefox()
    URL = 'https://steamdb.info/stats/toplevels/'
    
    driver.get(URL)   
    
    time.sleep(3)
    
    table_element = select_table(driver)
        
    # Recursive call to main to ensure controls are met
    while(len(table_element) < 1):
        driver.close()
        main()
    
    list_of_id_nums = parse_info(table_element)
    
    # Output array of steam id nums
    write_to_file(list_of_id_nums)
Example #23
0
def prepare_browser():
    # TODO: Test if the agents are properly applied.
    if random.choice([True, False]) is True:
        if DEBUG_MODE is True: log("Firefox won", "DEBUG")
        options = FirefoxOptions()
        agent = get_random_agent('firefox')
        profile = webdriver.FirefoxProfile()
        profile.set_preference("general.useragent.override", agent)
        # options.add_argument(f'user-agent={agent}')
        geckodriver_autoinstaller.install()
        if RUN_HEADLESS is True:
            options.add_argument('--headless')
            options.add_argument('--disable-gpu')
        return webdriver.Firefox(options=options)
    else:
        if DEBUG_MODE is True: log("Chromium won", "DEBUG")
        options = ChromeOptions()
        agent = get_random_agent('chrome')
        options.add_argument(f'user-agent={agent}')
        if RUN_HEADLESS is True:
            options.add_argument('--headless')
            options.add_argument('--disable-gpu')
        return uc.Chrome(options=options)
Example #24
0
 def setUp(self):
     geckodriver_autoinstaller.install()
     self.browser = webdriver.Firefox()
     self.client = Client()
     self.client = User.objects.create_user("usertest", "*****@*****.**",
                                            "Password3216854+")
     self.aliment = Aliment.objects.create(
         name="Tomates",
         name_fr="Tomates cerises",
         date="2019/01/09",
         brands="La Conserve",
         nutriscore="a",
         ingredients="Tomates, sel, sure, conservateurs",
         image="https://image-test-p8-url-test.com",
         url="https://test-p8-url-test.com",
         stores="Lidl, Auchan, Franprix",
         quantity="200g",
         packaging="Conserve",
         ingredients_fr="Tomates, sel, sucre",
         manufactured_places="Dijon",
         purchase_places="Bordeaux, Paris",
         categories="Légumes",
         code="654f654651651",
     )
Example #25
0
def get_twitch_oauth_token_implicit_flow():
    os.environ["AUTHLIB_INSECURE_TRANSPORT"] = "1"
    oauth_client = OAuth2Session(
        TWITCH_CLIENT_ID, scope="chat:read", redirect_uri=TWITCH_OAUTH_REDIRECT_URL
    )
    oauth_approve_url, _ = oauth_client.create_authorization_url(
        TWITCH_OAUTH_URL, response_type="token"
    )

    geckodriver_autoinstaller.install()
    with webdriver.Firefox() as driver:
        driver.get(oauth_approve_url)

        try:
            WebDriverWait(driver, 600).until(
                lambda d: d.current_url.startswith(TWITCH_OAUTH_REDIRECT_URL)
            )
        except TimeoutException as ex:
            raise RuntimeError("Could not get Twitch OAuth access token.") from ex

        oauth_response = oauth_client.fetch_token(
            authorization_response=driver.current_url
        )
        return oauth_response["access_token"]
Example #26
0
    def webdriver_init_path_kwarg(
            cls,
            user_passed_geckodriver_path: Optional[str] = None
    ) -> Dict[str, str]:
        firefox_kwargs = {}

        if user_passed_geckodriver_path and os.path.exists(
                user_passed_geckodriver_path):
            firefox_kwargs[
                Constants.
                WEBDRIVER_INIT_EXECUTABLE_PATH_KEYWORD] = user_passed_geckodriver_path
        elif not cls.is_geckodriver_installed():
            firefox_kwargs[
                Constants.
                WEBDRIVER_INIT_EXECUTABLE_PATH_KEYWORD] = geckodriver_autoinstaller.install(
                )

        return firefox_kwargs
Example #27
0
import geckodriver_autoinstaller
try:
    geckodriver_autoinstaller.install()
except OSError:
    print("could not intall geckodriver, please install manually and add to PTAH")
Example #28
0
 def __init__(self):
     # create a new Firefox session
     geckodriver_autoinstaller.install()
     self.driver = webdriver.Firefox()
     self.driver.implicitly_wait(30)
     self.driver.set_window_size(1120, 1000)
Example #29
0
def setup():
    chromedriver_autoinstaller.install()
    geckodriver_autoinstaller.install()
Example #30
0
# Write your code here :-)
from selenium import webdriver
import geckodriver_autoinstaller

geckodriver_autoinstaller.install(
)  # Check if the current version of geckodriver exists
# and if it doesn't exist, download it automatically,
# then add geckodriver to path

driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title