I am trying to download a file using python headless chrome web driver. My code is running to slow.There is no output(downloaded) file. I am getting no error. Any help would be appreciated. here is my code:
# Getting All User Credintials
for x in range(2,st.max_row + 1):
Users.append([st.cell(x, 1).value,st.cell(x, 2).value, st.cell(x, 3).value])
# Looping through Users
for item in Users:
try:
chrome_options = Options()
chrome_options.add_argument("--headless")
prefs = {"download.default_directory": os.getcwd()}
chrome_options.add_experimental_option("prefs", prefs)
chrome = webdriver.Chrome(chrome_options=chrome_options)
chrome.get(Url)
chrome.find_element_by_id("formId:codEmpresa").send_keys(item[0]) # Enterinng login Credintials
chrome.find_element_by_id("formId:codUsuario").send_keys(item[1])
chrome.find_element_by_id("formId:senha").send_keys(item[2])
chrome.find_element_by_link_text("Entrar").click() # Clicking Login button
chrome.get("https://www3.honda.com.br/newihs/AbrirPag?Opcao=1998")
chrome.find_element_by_name("W0002vWDINI").send_keys(DateFrom) # Entering DateForm
chrome.find_element_by_name("W0002vWDFIM").send_keys(DateTo) # Entering DateTo
chrome.find_element_by_name("W0002BT_CONFIRMAR").click() # Clicking Confirm button
wait = WebDriverWait(chrome, 10)
element = wait.until(EC.element_to_be_clickable((By.NAME, 'W0002BT_INFORMAR2')))
chrome.find_element_by_name("W0002BT_INFORMAR2").click() # Clicking Download button
Diable the proxy amd try, It should increase perfromance
chrome_options.add_argument('--no-proxy-server')
I found that it helped me.
In addition to iamsankalp89 answer:
chrome_options.add_argument('--no-proxy-server')
these additional options helped me to drastically increase the performance:
chrome_options.add_argument("--proxy-server='direct://'");
chrome_options.add_argument("--proxy-bypass-list=*");
(Source: from this issue on GitHub and this comment in particular)
来源:https://stackoverflow.com/questions/51503437/headless-chrome-web-driver-too-slow-and-unable-to-download-file