一、自动保存文件
import os from selenium import webdriver
fp = webdriver.FirefoxProfile() fp.set_preference("browser.download.folderList",2) fp.set_preference("browser.download.manager.showWhenStarting",False) fp.set_preference("browser.download.dir", os.getcwd()) fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream") browser = webdriver.Firefox(firefox_profile=fp) browser.get("http://pypi.python.org/pypi/selenium") browser.find_element_by_partial_link_text("selenium-2").click()
一旦确定内容类型,您可以使用它来设置firefox配置文件的偏好:browser.helperApps.neverAsk.saveToDisk
该选项指定您想要下载的文件的目录:browser.download.dir
二、模拟手机访问m站
#coding=utf-8 from selenium import webdriver op = webdriver.FirefoxProfile() op.set_preference('general.useragent.override','Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.76 Mobile Safari/537.36') driver = webdriver.Firefox(firefox_profile=op) driver.get('http://m.taobao.com')
更多参数可以在火狐地址栏输入:about:config
或查看:http://kb.mozillazine.org/Firefox_:_FAQs_:_About:config_Entries