我正试图使用selenium
从FanGraphs Leaderboards下载一些数据。我是用Firefox来实现的,但是Chrome的速度快了一点,所以我试着切换到那个。在Firefox中,下载文件是可行的,但我在切换到Chrome时遇到了麻烦
chrome_options = webdriver.ChromeOptions()
chrome_options.headless = False
os.makedirs("dist", exist_ok=True)
preferences = {
"profile.default_content_settings.popups": 0,
"download.default_directory": "dist/",
"directory_upgrade": True
}
chrome_options.add_experimental_option(
"prefs", preferences
)
self.browser = webdriver.Chrome(
chrome_options=chrome_options
)
while True:
try:
WebDriverWait(self.browser, 20).until(
expected_conditions.element_to_be_clickable(
(By.ID, "LeaderBoard1_cmdCSV")
)
).click()
break
except exceptions.ElementClickInterceptedException:
self.__close_ad()
每当我为模块运行测试时,CSV文件都会出现在C:/Users/UserDir/Downloads,而不是当前工作目录中的dist/文件夹中。我仔细检查了dist/文件夹是否存在,它确实存在
selenium
v3.141.0
我也有同样的问题,我也解决了
目录\u升级可能会错过下载。之前
复制并粘贴这个
相关问题 更多 >
编程相关推荐