【问题标题】:Download file from sharepoint using selenium webdriver python使用 selenium webdriver python 从共享点下载文件
【发布时间】:2015-04-23 07:43:08
【问题描述】:

我正在尝试从共享点 url 下载文件并将代码写入neverask.savetodisk,但它仍然显示保存文件的对话框。我尝试了相同的代码,当我们单击其他 URL 的下载链接但无法使用 sharepoint 应用程序时,它可以工作。这是我使用的代码...

from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile

# To prevent download dialog
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2) # custom location
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference("browser.download.defaultFolder",'tt_at');
profile.set_preference("browser.download.lastDir",'tt_at');
profile.set_preference('browser.download.dir', 'tt_at')
profile.set_preference("browser.download.useDownloadDir",True);
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', "application/octet-stream,application/msexcel")

browser = webdriver.Firefox(profile)
browser.get("https://docs.ad.sys.com/sites/cloud/Project/Form/FolderCTID=0x01200069047C40C93C3846B74E0776AAD1610A&InitialTabId=Ribbon%2EDocument&VisibilityContext=WSSTabPersistence")  
browser.find_element_by_xpath('/html/body/form/div[8]/div/div[3]/div[3]/div[2]/div/div/table/tbody/tr/td/table/tbody/tr/td/div/table[1]/tbody/tr/td/table/tbody/tr[12]/td[4]/div[1]/a').click()

但上面的代码仍然显示选择位置的对话框。

【问题讨论】:

标签: python selenium sharepoint selenium-webdriver download


【解决方案1】:

我想我找到了解决方案,请尝试以下方法:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
profile = webdriver.FirefoxProfile()
#Give Complete Path of download dir
profile.set_preference("browser.download.lastDir",r'd:\temp')
profile.set_preference("browser.download.useDownloadDir",True)
profile.set_preference("browser.download.manager.showWhenStarting",False)
profile.set_preference('browser.helperApps.neverAsk.saveToDisk',"application/vnd.ms-excel,Content-Type=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/octet-stream")
profile.set_preference('browser.helperApps.neverAsk.openFile', "application/vnd.ms-excel,Content-Type=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/octet-stream")
browser = webdriver.Firefox(profile)
browser.get("https://docs.ad.sys.com/sites/cloud/Project/Form/FolderCTID=0x01200069047C40C93C3846B74E0776AAD1610A&InitialTabId=Ribbon%2EDocument&VisibilityContext=WSSTabPersistence")  
browser.find_element_by_xpath('/html/body/form/div[8]/div/div[3]/div[3]/div[2]/div/div/table/tbody/tr/td/table/tbody/tr/td/div/table[1]/tbody/tr/td/table/tbody/tr[12]/td[4]/div[1]/a').click()

如果这也不适合您,请执行以下操作,在 firefox 中安装插件 tamperdata 并观察您尝试下载的文件的内容类型,然后将该确切文本添加到“browser.helperApps.neverAsk” 。*“ 偏爱。这将解决您的问题!

【讨论】:

    猜你喜欢
    • 2023-03-31
    • 1970-01-01
    • 2017-08-26
    • 1970-01-01
    • 2020-01-09
    • 1970-01-01
    • 2014-09-15
    • 2021-03-20
    • 2014-07-23
    相关资源
    最近更新 更多