abdelgha4
abdelgha4

Reputation: 431

How to use seleniumbase in Streamlit cloud

There are a few ressources on how to run selenium in Streamlit cloud with chromium, and this example with google-chrome-stable. But I couldn't find any specific instructions for seleniumbase.

Following the later example, it fails with seleniumbase when trying to download the UC driver (I'm interested in CDP mode).

Here is the content of my packages.txt:

chromium
chromium-driver
google-chrome-stable
pkg-config
python3-dev
python3-tk
xvfb

Error traceback:

Warning: uc_driver not found. Getting it now:

*** chromedriver to download = 131.0.6778.87 (Latest Stable) 

Downloading chromedriver-linux64.zip from:
https://storage.googleapis.com/chrome-for-testing-public/131.0.6778.87/linux64/chromedriver-linux64.zip ...
────────────────────── Traceback (most recent call last) ───────────────────────
  /home/adminuser/venv/lib/python3.12/site-packages/seleniumbase/core/browser_  
  launcher.py:4836[2024-12-09 20:26:24.074470]  in get_local_driver                                          
                                                                                
    4833 │   │   │   │   │   │   │   │   uc_path = LOCAL_UC_DRIVER              
    4834 │   │   │   │   │   │   │   │   uc_path = os.path.realpath(uc_path)    
    4835 │   │   │   │   │   │   │   try:                                       
  ❱ 4836 │   │   │   │   │   │   │   │   driver = undetected.Chrome(            
    4837 │   │   │   │   │   │   │   │   │   options=chrome_options,            
    4838 │   │   │   │   │   │   │   │   │   user_data_dir=user_data_dir,       
    4839 │   │   │   │   │   │   │   │   │   driver_executable_path=uc_path,    
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/seleniumbase/undetected/__  
  init__.py:130 in __init__                                                     
                                                                                
    [2024-12-09 20:26:24.074774] 127 │   │   │   │   │   force=patcher_force_close,                          
    128 │   │   │   │   │   version_main=version_main,                          
    129 │   │   │   │   )                                                       
  ❱ 130 │   │   │   │   self.patcher.auto()                                     
    131 │   │   if not options:                                                 
    132 │   │   │   options = ChromeOptions()                                   
    133 │   │   try:                                                            
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/seleniumbase/undetected/pa  
  tcher.py:106 in auto                                                          
                                                                                
    103 │   │   │   │   pass                                                    
    104 │   │   except FileNotFoundError:                                       
    105 │   │   │   pass                                                        
  ❱ 106 │   │   release = self.fetch_release_number()                           
    107 │   │   self.version_main = release.split(".")[0]                       
    108 │   │   self.version_full = release                                     
    109 │   │   self.unzip_package(self.fetch_package())                        
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/seleniumbase/undetected/pa  
  tcher.py:124 in fetch_release_number                                          
                                                                                
    121 │   │   │   path += "_[2024-12-09 20:26:24.075098] %s" % self.version_main                           
    122 │   │   path = path.upper()                                             
    123 │   │   logger.debug("Getting release number from %s" % path)           
  ❱ 124 │   │   return urlopen(self.url_repo + path).read().decode()            
    125 │                                                                       
    126 │   def fetch_package(self):                                            [2024-12-09 20:26:24.075304] 
    127 │   │   """Downloads chromedriver from source.                          
                                                                                
  /usr/local/lib/python3.12/urllib/request.py:215 in urlopen                    
                                                                                
     212 │   │   _opener = opener = build_opener()                              
     213 │   else:                                                              
     214 │   │   opener = _opener                                               
  ❱  215 │   return opener.open(url, data, timeout)                             
     216                                                                        
     217 def install_opener(opener):                                            
     218 │   global _opener                                                     
 [2024-12-09 20:26:24.075862]                                                                                
  /usr/local/lib/python3.12/urllib/request.py:521 in open                       
                                                                                
     518 │   │   meth_name = protocol+"_response"                               
     519 │   │   for processor in [2024-12-09 20:26:24.076173] self.process_response.get(protocol, []):      
     520 │   │   │   meth = getattr(processor, meth_name)                       
  ❱  521 │   │   │   response = meth(req, response)                             
     522 │   │                                                                  
     523 │   │   return response                                                
     524                                                                        
                                                                                
  /usr/local/lib/python3.12/urllib/request.py:630 in http_response              [2024-12-09 20:26:24.076659] 
                                                                                
     627 │   │   # According to RFC 2616, "2xx" code indicates that the client  
     628 │   │   # request was successfully received, understood, and accepted  
     629 │   │   [2024-12-09 20:26:24.076965] if not (200 <= code < 300):                                    
  ❱  630 │   │   │   response = self.parent.error(                              
     631 │   │   │   │   'http', request, response, code, msg, hdrs)            
     632 │   │                                                                  
     633 [2024-12-09 20:26:24.077182] │   │   return response                                                
                                                                                
  /usr/local/lib/python3.12/urllib/request.py:559 in error                      
                                                                                
     556 │   │                                                                  
     557 │   │   if http_err:                                                   
     558 │   │   │   args = ([2024-12-09 20:26:24.077407] dict, 'default', 'http_error_default') + orig_arg  
  ❱  559 │   │   │   return self._call_chain(*args)                             
     560                                                                        
     561 # XXX probably also want an abstract factory that knows when it makes  
     562 # sense to skip a superclass in favor of a subclass and when it might  
                                                                                
  /usr/local/lib/python3.12/urllib/request.py:492 in _call_chain                
                                                                                
     489 │   │   handlers = chain.get(kind, ())                                 
     490 │   │   for handler in handlers:                                       
     491 │   │   │   func = getattr(handler, meth_name)                         
  ❱  492 │   │   │   result = func(*args)                                       
     493 │   │   │   if result is not None:                                     
     494 │   │   │   │   return result                                          
     495                                                                        
                                                                                
  /usr/local/lib/python3.12/urllib/request.py:639 in http_error_default         
                                                                                
     636                                                                        
     637 class HTTPDefaultErrorHandler(BaseHandler):                            
     638 │   def http_error_default(self, req, fp, code, msg, hdrs):            
  ❱  639 │   │   raise HTTPError(req.full_url, code, msg, hdrs, fp)             
     640                                                                        
     641 class [2024-12-09 20:26:24.078245] HTTPRedirectHandler(BaseHandler):                                
     642 │   # maximum number of redirections to any single URL                 
────────────────────────────────────────────────────────────────────────────────
HTTPError: HTTP Error 404: Not Found

Upvotes: 0

Views: 25

Answers (0)

Related Questions