1 profile = FirefoxProfile()
2 #请求头
3 #profile.set_preference("general.useragent.override", util.http_agent_insert(xinhuaUtil.agent_path))
4 # 激活手动代理配置(对应着在 profile(配置文件)中设置首选项)
5 profile.set_preference("network.proxy.type", 1)
6
7 # ip及其端口号配置为 http 协议代理
8 #profile.set_preference("network.proxy.http", str(proxy[0])) #ip
9 #profile.set_preference("network.proxy.http_port", int(proxy[1])) #端口
10
11 # 所有协议共用一种 ip 及端口,如果单独配置,不必设置该项,因为其默认为 False
12 profile.set_preference("network.proxy.share_proxy_settings", True)
13
14 # 默认本地地址(localhost)不使用代理,如果有些域名在访问时不想使用代理可以使用类似下面的参数设置
15 profile.set_preference("network.proxy.no_proxies_on", "localhost")
16
17 # 禁用浏览器缓存
18 profile.set_preference("network.http.use-cache", False)
19 profile.set_preference("browser.cache.memory.enable", False)
20 profile.set_preference("browser.cache.disk.enable", False)
21 profile.set_preference("browser.sessionhistory.max_total_viewers", 3)
22 profile.set_preference("network.dns.disableIPv6", True)
23 profile.set_preference("Content.notify.interval", 750000)
24 profile.set_preference("content.notify.backoffcount", 3)
25 # 有的网站支持 有的不支持
26 profile.set_preference("network.http.pipelining", True)
27 profile.set_preference("network.http.proxy.pipelining", True)
28 profile.set_preference("network.http.pipelining.maxrequests", 32)
29
30 #禁用图片
31 profile.set_preference('permissions.default.image', 2) # 某些firefox只需要这个
32 profile.set_preference('browser.migration.version', 9001) # 部分需要加上这个
33 #禁用css
34 profile.set_preference('permissions.default.stylesheet', 2)
35 #禁用flash
36 profile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so', 'false')
37 #禁用js
38 profile.set_preference('javascript.enabled', 'false')
39
40 profile.update_preferences()
41 # 以代理方式启动 firefox
42 firefox = webdriver.Firefox(profile)