AttributeError: 'Browserbot' object has no attribute '_Browserbot__capabilities' selenium python

Viewed 27

I am getting this error "AttributeError: 'Browserbot' object has no attribute '_Browserbot__capabilities'" I want to make a web scraping app and set all the browser configuration in one file and the scraping procedure in other file, so I can call the scraping file in the run.py.

this is the code


import os
import sys
import time
import logging
from selenium import webdriver
from webdriver_manager.core.utils import ChromeType
from webdriver_manager.chrome import ChromeDriverManager
from selenium.common.exceptions import TimeoutException
from scraping.browser_manager import constants as const
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

CHROMEDRIVER_PATH = r"C:\Users\Narsil\dev\seleniumDrivers\chromedriver.exe"

class Browserbot(webdriver.Chrome):


    def __init__(self, driver_path=CHROMEDRIVER_PATH, teardown=False, headless=True, time_out=0, capabilities=False):
        
        """
        variables 
        """
        self.__headless = headless
        self.driver_path = driver_path
        self.teardown = teardown

        # Desable modules logs
        logging.disable(logging.DEBUG)
        
        # Create and instance of the web browser 
        self.__set_browser_instance()
        
        # Get current file name
        self.current_file = os.path.basename(__file__)
        
        # Set time out 
        if time_out > 0: 
            self.driver.set_page_load_timeout(30)
    
    def __set_browser_instance(self):
        """
        Open and configure browser
        """
        
        # Disable logs
        os.environ['WDM_LOG_LEVEL'] = '0'
        os.environ['WDM_PRINT_FIRST_LINE'] = 'False'
        """
        configure browser
        """
        options = webdriver.ChromeOptions()
        options.add_argument('--no-sandbox')
        options.add_argument('--start-maximized')
        options.add_argument('--output=/dev/null')
        options.add_argument('--log-level=3')
        options.add_argument("--disable-notifications");
        options.add_argument("disable-infobars");
        options.add_experimental_option('excludeSwitches', ['enable-logging'])

        if self.__headless:        
            options.add_argument("--window-size=1920,1080")
            options.add_argument("--headless")

        if self.__capabilities:
            capabilities = DesiredCapabilities.CHROME
            capabilities["goog:loggingPrefs"] = {"performance": "ALL"}
        else: 
            capabilities = None

         # Set configuration to  and create instance
        while True:
            print ("\ttrying to open browser...")
            try: 
                chromedriver = ChromeDriverManager(chrome_type=ChromeType.GOOGLE, 
                                            log_level='0', 
                                            print_first_line=False).install()
            except:
                continue
            else:
                break

        self.driver = webdriver.Chrome(chromedriver, 
                                options=options, 
                                service_log_path=None, 
                                desired_capabilities=capabilities) 

        if self.__web_page: 
            self.driver.get(const.BASE_URL)                               
    

    def __exit__(self, exc_type, exc_val, exc_tb):
        if self.teardown:
            self.quit()

and this is other dependencies where I will set the selector scraping elements.

import time
import os
from scraping.browser_manager.automate_browser import Browserbot
from scraping.browser_manager import constants as const
from selenium import webdriver 
from selenium.webdriver.common.by import By



class Webscraping:
    
    def __init__(self):

        # self.scraper instance
        
        self.scraper = Browserbot()

    def accept_cookies(self):
        cookies = self.find_element(By.CSS_SELECTOR,
           '.sui-TcfFirstLayer-buttons > button:nth-child(2)'
        )
        time.sleep(5)
        cookies.click()

I thinks this error could be wrong syntax for calling the class, but I am not sure.

below the run.py file

from scraping.scraper import Webscraping

try:

    with Webscraping() as bot:
         bot.Webscraping()
0 Answers
Related