0

I'm trying to download some zips files from this page to an specific path for an already chrome browser session open using the code down below:

import time
import numpy as np
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

opt = Options() #the variable that will store the selenium options
opt.add_experimental_option("debuggerAddress", "localhost:9222") #this allows bulk-dozer to take control of your Chrome Browser in DevTools mode.
opt.add_experimental_option("prefs", {"download.default_directory": r"C:\Users\ResetStoreX\Downloads\Binance futures data\ADAUSDT-Mark_Prices_Klines_1h_Timeframe"}) #set the path to save the desired zipped data 
s = Service(r'C:\Users\ResetStoreX\AppData\Local\Programs\Python\Python39\Scripts\chromedriver.exe') #Use the chrome driver located at the corresponding path
driver = webdriver.Chrome(service=s, options=opt) #execute the chromedriver.exe with the previous conditions

#Why using MarkPrices: https://support.btse.com/en/support/solutions/articles/43000557589-index-price-and-mark-price#:~:text=Index%20Price%20is%20an%20important,of%20cryptocurrencies%20on%20major%20exchanges.&text=Mark%20Price%20is%20the%20price,be%20fair%20and%20manipulation%20resistant.

if driver.current_url == 'https://data.binance.vision/?prefix=data/futures/um/daily/markPriceKlines/ADAUSDT/1h/' :   
    number = 2 #initialize an int variable to 2 because the desired web elements in this page starts from 2
    counter = 0
    the_dictionary_links = {}
    while number <= np.size(driver.find_elements(By.XPATH, '//*[@id="listing"]/tr')): #iterate over the tbody array
        data_file_name = driver.find_element(By.XPATH, f'//*[@id="listing"]/tr[{number}]/td[1]/a').text
        if data_file_name.endswith('CHECKSUM') == False:
            the_dictionary_links[data_file_name] = driver.find_element(By.XPATH, f'//*[@id="listing"]/tr[{number}]/td[1]/a').get_attribute('href')
            print(f'Saving {data_file_name} and its link for later use')
            counter += 1            
        number += 1
    print(counter)
    i = 0
    o = 0
    for i,o in the_dictionary_links.items():
        driver.get(o)
        print(f'Downloading {i}')
        time.sleep(1.8)

And unfortunately it's not working, it throws the following error:

InvalidArgumentException: invalid argument: cannot parse capability: goog:chromeOptions from invalid argument: unrecognized chrome option: prefs

So, I would like to know what could have gone wrong? I coded the program above based on this solution but it only seems to work for a new chrome session, and I need the download default directory to be capable of being reset when needed for an already open session. Any ideas?

NoahVerner
  • 683
  • 3
  • 13

0 Answers0