我正在尝试使用python无头chrome网络驱动程序下载文件。我的代码运行缓慢。没有输出(下载)文件。我没有任何错误。任何帮助,将不胜感激。 这是我的代码:
# 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
答案 0 :(得分:2)
除了iamsankalp89答案:
chrome_options.add_argument('--no-proxy-server')
这些其他选项帮助我大大提高了性能:
chrome_options.add_argument("--proxy-server='direct://'");
chrome_options.add_argument("--proxy-bypass-list=*");
(来源:来自此issue on GitHub,尤其是来自此comment)
答案 1 :(得分:1)
禁用代理和尝试,应该提高性能
chrome_options.add_argument('--no-proxy-server')
我发现它对我有帮助。
答案 2 :(得分:1)
这应该会有所帮助(C#)
chromeoptions.AddArguments("--headless", "--window-size=1920,1200");