標籤:
Selenium操作瀏覽器是不載入任何配置的,網上找了半天,關於Firefox載入配置的多點,Chrome資料很少,下面是關於載入Chrome配置的方法:
一、載入所有Chrome配置
用Chrome地址欄輸入chrome://version/,查看自己的“設定檔路徑”,然後在瀏覽器啟動時,調用這個設定檔,代碼如下:
#coding=utf-8from selenium import webdriveroption = webdriver.ChromeOptions()option.add_argument(‘--user-data-dir=C:\Users\Administrator\AppData\Local\Google\Chrome\User Data‘) #設定成使用者自己的資料目錄driver = webdriver.Chrome(chrome_options=option)
二、修改瀏覽器的User-Agent來偽裝你的瀏覽器訪問手機m站
#coding=utf-8from selenium import webdriveroption = webdriver.ChromeOptions()option.add_argument(‘--user-agent=iphone‘)driver = webdriver.Chrome(chrome_options=option)driver.get(‘http://www.taobao.com/‘)
三、瀏覽器啟動時安裝crx擴充
#coding=utf-8from selenium import webdriveroption = webdriver.ChromeOptions()option.add_extension(‘d:\crx\AdBlock_v2.17.crx‘) #自己下載的crx路徑driver = webdriver.Chrome(chrome_options=option)driver.get(‘http://www.taobao.com/‘)
可以去https://sites.google.com/a/chromium.org/chromedriver/capabilities查看更多,或者去http://stackoverflow.com/尋找。
下邊是收集的一些配置資訊:
一些Chrome的地址欄命令(這些命令會不停的變動,所有不一定都是好用的)
在Chrome的瀏覽器地址欄中輸入以下命令,就會返回相應的結果。這些命令包括查看記憶體狀態,瀏覽器狀態,網路狀態,DNS伺服器狀態,外掛程式緩衝等等。
about:version - 顯示目前的版本
about:memory - 顯示本機瀏覽器記憶體使用量狀況
about:plugins - 顯示已安裝外掛程式
about:histograms - 顯示記錄
about:dns - 顯示DNS狀態
about:cache - 顯示快取頁面面
about:gpu -是否有硬體加速
about:flags -開啟一些外掛程式 //使用後彈出這麼些東西:“請小心,這些實驗可能有風險”,不知會不會搞亂俺的配置啊!
chrome://extensions/ - 查看已經安裝的擴充
其他的一些關於Chrome的實用參數及簡要的中文說明(使用方法同上,當然也可以在shell中使用)
–user-data-dir=”[PATH]” 指定使用者檔案夾User Data路徑,可以把書籤這樣的使用者資料儲存在系統磁碟分割以外的分區。
–disk-cache-dir=”[PATH]“ 指定緩衝Cache路徑
–disk-cache-size= 指定Cache大小,單位Byte
–first run 重設到初始狀態,第一次運行
–incognito 隱藏模式啟動
–disable-javascript 禁用Javascript
--omnibox-popup-count="num" 將地址欄彈出的提示菜單數量改為num個。我都改為15個了。
--user-agent="xxxxxxxx" 修改HTTP要求標頭部的Agent字串,可以通過about:version頁面查看修改效果
--disable-plugins 禁止載入所有外掛程式,可以增加速度。可以通過about:plugins頁面查看效果
--disable-javascript 禁用JavaScript,如果覺得速度慢在加上這個
--disable-java 禁用java
--start-maximized 啟動就最大化
--no-sandbox 取消沙箱模式
--single-process 單進程運行
--process-per-tab 每個標籤使用單獨進程
--process-per-site 每個網站使用單獨進程
--in-process-plugins 外掛程式不啟用單獨進程
--disable-popup-blocking 禁用彈出攔截
--disable-plugins 禁用外掛程式
--disable-images 禁用映像
--incognito 啟動進入隱藏模式
--enable-udd-profiles 啟用賬戶切換菜單
--proxy-pac-url 使用pac代理 [via 1/2]
--lang=zh-CN 設定語言為簡體中文
--disk-cache-dir 自訂緩衝目錄
--disk-cache-size 自訂緩衝最大值(單位byte)
--media-cache-size 自訂多媒體緩衝最大值(單位byte)
--bookmark-menu 在工具 欄增加一個書籤按鈕
--enable-sync 啟用書籤同步
selenium啟動Chrome時,載入使用者設定檔