Selenium+python Automation 80-File download (Do not play inquiry box)

Source: Internet
Author: User

Objective

The previous article is a button on the pop-up box to save the file, this article describes a more elegant way to load Firefox and chrome configuration files, do not pop up the query box background download.

First, Firefoxprofile

1. Click on the download, such as, if you do not want it to pop up this query box, you can load Firefox configuration file hidden.

2. Set the parameters, parameters can be entered in the browser address bar About:config view

Configuration instructions for 3.FirefoxProfile

-' browser.download.folderList ': set to 0 to download to the desktop, set to 1 to download to the default path, set to 2 can be saved to the specified directory;

-' Browser.download.dir ': "Set a local computer path: ' d:\\ '"

-"browser.download.manager.showWhenStarting", False whether the download Progress box is shown (this setting does not take effect)

-"Browser.helperApps.neverAsk.saveToDisk", "Application/octet-stream" for the given file type no longer popup box to inquire

Ii. Types of files

1. Fourth parameter file Type here it is important to note that the different file types downloaded, the parameters are not the same, can be consulted: MIME reference manual http://www.w3school.com.cn/media/media_mimeref.asp

Third, Firefox configuration

#Coding:utf-8 fromSeleniumImportWebdriver#To set the parameters , the parameters can be viewed by entering about:config in the browser address bar. Profile =Webdriver. Firefoxprofile ()#set to 0 to download to the desktop, set to 1 for download to the default path, set to 2 can be saved to the specified directory;Profile.set_preference ('browser.download.folderList', 2)#Specify the download file to the path you want to placeProfile.set_preference ('Browser.download.dir','d:\\')#Show whether the progress box is displayed when the download starts (this setting is not currently in effect)Profile.set_preference ("browser.download.manager.showWhenStarting", False)#ask for the file type no longer popup boxProfile.set_preference ("Browser.helperApps.neverAsk.saveToDisk","Application/octet-stream") Driver= Webdriver. Firefox (firefox_profile=Profile )#Open Youdao Cloud notesDriver.get ("http://note.youdao.com/")#Click the Download Now buttonDRIVER.FIND_ELEMENT_BY_ID ("download-btn"). Click () Four, chrome configuration#Coding:utf-8 fromSeleniumImportWebdriverprofile=Webdriver. Chromeoptions () prefs= {'profile.default_content_settings.popups': 0,#set to 0 to suppress pop-up windows         'download.default_directory':'d:\\'}#Specify the download pathProfile.add_experimental_option ('prefs', Prefs)#Executable_path This is the path to chromedriver. If the environment variable is set, this parameter can be omittedChromedriver_path ="D:\\path\\chromedriver.exe"   #own local computer pathDriver = Webdriver. Chrome (Executable_path=chromedriver_path, chrome_options=Profile )#Open Youdao Cloud notesDriver.get ("http://note.youdao.com/")#Click the Download Now buttonDRIVER.FIND_ELEMENT_BY_ID ("download-btn"). Click ()

Selenium+python Automation 80-File download (Do not play inquiry box)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.