python - multiple download folders using Selenium Webdriver? -


i'm using selenium webdriver (in python) automate donwloading of thousands of files. want files saved in different folders. following code works, requires quitting , re-starting webdriver multiple times, slows down process:

some_list = ["item1", "item2", "item3"] # on 300 items on actual code item in some_list:     download_folder = "/users/myusername/desktop/" + item     os.makedirs(download_folder)     fp = webdriver.firefoxprofile()     fp.set_preference("browser.download.folderlist", 2)     fp.set_preference("browser.download.manager.showwhenstarting", false)     fp.set_preference("browser.download.dir", download_folder)     fp.set_preference("browser.helperapps.neverask.savetodisk", "text/plain")     browser = webdriver.firefox(firefox_profile = fp)      # bunch of code accesses site , downloads files      browser.close()     browser.quit() 

so, @ every iteration have quit webdriver , re-start it, pretty innefficient. there better way this? apparently can't change firefox profile after webdriver instantiated (see this , this previous questions), perhaps there alternative i'm missing?

(mac os x 10.6.8, python 2.7.5, selenium 2.2.0)

no, don't think can it.

option one: specify different default directories 1 firefoxprofile

you can't. in opinion, issue firefox, not selenium. however, firefox limitation looks correct design me. browser.download.dir default download destination, if allows multiple directories, that's not "default" anymore.

option two: switch multiple firefoxprofile 1 driver instance

if not doing in firefox, can firefoxprofile switched same driver instance? far know, answer no. (you have done research on this)

option three: use normal non-selenium way downloading

if want avoid using auto-downloading approach , normal way (like auto-it etc.), falls in category of "how download files selenium , why shouldn’t". in case, code can simplified.

some_list = ["item1", "item2", "item3"] # on 300 items on actual code item in some_list:     download_folder = "/users/myusername/desktop/" + item     some_way_magically_do_the_downloading(download_folder) 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -