You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Selenium Python脚本导出大文件时在文件生成完成前超时的问题求助

Selenium Python脚本导出大文件时在文件生成完成前超时的问题求助

大家好,我最近写了一段Selenium Python脚本,想从网站导出CSV文件,但遇到了棘手的超时问题,想请各位帮忙看看。

这段脚本的逻辑是进入后台产品列表页,选择特定分类后执行搜索,再触发导出全部数据的操作,代码如下:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
import time

def run():
    print('running')
    driver = webdriver.Chrome()
    driver.set_page_load_timeout(2000)
    driver.set_window_size(1024, 600)
    driver.maximize_window()
    try:
        driver.get("https://www.pjdsafetysupplies.com/Admin/Product/List")
        selectElement = Select(driver.find_element(By.ID, "SearchCategoryId"))
        selectElement.select_by_visible_text('Special Offers')
        search = driver.find_element(By.ID, 'search-products')
        search.click()
        driver.find_element(By.XPATH,".//button[@data-toggle='dropdown']").click()
        driver.find_element(By.XPATH,".//button[@name='exportexcel-all']").click()
    except Exception as e:
        print("Page Load Fail:"+str(e))
    finally:
        driver.quit()


run()

问题出在网站生成的文件体积很大,脚本总是在文件创建完成前就超时了,报错信息如下:

HTTPConnectionPool(host='localhost', port=54896): Read timed out. (read timeout=120)

我已经尝试把set_page_load_timeout设成2000了,但错误信息里还是显示读取超时为120。另外我也试过设置implicit_wait和脚本超时参数,结果还是出现同样的错误,实在摸不着头绪,希望大家能给点解决思路!

备注:内容来源于stack exchange,提问作者Matthew Wallace

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 13:07:59