Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 无头chrome web驱动程序太慢,无法下载文件_Python 3.x_Selenium Webdriver_Download_Google Chrome Headless - Fatal编程技术网

Python 3.x 无头chrome web驱动程序太慢,无法下载文件

Python 3.x 无头chrome web驱动程序太慢,无法下载文件,python-3.x,selenium-webdriver,download,google-chrome-headless,Python 3.x,Selenium Webdriver,Download,Google Chrome Headless,我正在尝试使用python无头chrome web驱动程序下载一个文件。我的代码运行速度太慢。没有输出(下载)文件。我没有错。任何帮助都将不胜感激。 这是我的密码: # 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 Us

我正在尝试使用python无头chrome web驱动程序下载一个文件。我的代码运行速度太慢。没有输出(下载)文件。我没有错。任何帮助都将不胜感激。 这是我的密码:

# 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

禁用代理并重试,它将提高性能

chrome_options.add_argument('--no-proxy-server') 
我发现这对我很有帮助。

除了回答:

这些附加选项帮助我大幅提高了性能

chrome_options.add_argument("--proxy-server='direct://'");
chrome_options.add_argument("--proxy-bypass-list=*");
(来源:从这个,特别是从这个)这应该会有帮助(C#)


这是金子^_^谢谢你@teoretic。这个选项真的提高了性能!!!
chrome_options.add_argument("--proxy-server='direct://'");
chrome_options.add_argument("--proxy-bypass-list=*");
chromeoptions.AddArguments("--headless", "--window-size=1920,1200");