#Coding=utf-8 fromSeleniumImportWebdriver#instantiate a Firefox configuration fileFP =Webdriver. Firefoxprofile ()#To set the parameters , the parameters can be viewed by entering about:config in the browser address bar. #set to 0 for download to browser default download path; set to 2 to save to the specified directoryFp.set_preference ("browser.download.folderList", 2)#whether the display starts, (individual experiments, whether set to True or false, do not show start, direct download)Fp.set_preference ("browser.download.manager.showWhenStarting", False)#download to the specified directoryFp.set_preference ("Browser.download.dir","c:\\temp")#do not ask for the download path; The following parameter is the value of the Content-type to download the pageFp.set_preference ("Browser.helperApps.neverAsk.saveToDisk","Application/octet-stream")#start a Firefox process with just the browser parametersDriver = Webdriver. Firefox (firefox_profile=FP)#Open the download pageDriver.get ("Https://pypi.python.org/pypi/selenium")#Click on a buttonDriver.find_element_by_xpath ("//*[@id = ' content ']/div[3]/table/tbody/tr[2]/td[1]/span"). Click ()
Python+selenium Automation Implementation Example-implement file download