from bs4 import BeautifulSoup
import requests
from trawler.browsers import exceptions
from trawler.browsers.utils import start_browser
import logging
import random, time
from trawler.settings import AVAILABLE_METHODS, DEFAULT_MAX_PAGES
from user_agent import generate_user_agent
from datetime import datetime

logging.getLogger(__name__)


class BrowserBase(object):
    """
    Base class for making new browser classes like BingBrowser, GoogleBrowser, DuckDuckGoBrowser etc
    
    
    USAGE:
        _BASE_URL : https://www.bing.com # this should be changed for each Child class
        _PHANTOMJS_PATH : #phantomjs binary path
        _DEFAULT_METHOD : #default method used to scrape ? selenium-chrome or selenium-htmlunit
        
    """

    def __init__(self, kw=None, max_page=None, method='selenium-chrome', driver=None):
        """
        Make some quick calculations to proceed with the run
        """

        self._AVAILABLE_SCRAPE_METHODS = AVAILABLE_METHODS

        self._BASE_URL = None
        self._SEARCH_QS = None
        self._SEARCH_TERM = None
        self._SEARCH_URL = self._BASE_URL
        if self._SEARCH_QS: self._SEARCH_URL = self._SEARCH_URL + self._SEARCH_QS
        if self._SEARCH_TERM: self._SEARCH_URL = self._SEARCH_URL + self._SEARCH_TERM