Chrome啟動引數 無介面等

2022-09-12 02:24:15 字數 1999 閱讀 2600

引數:--headless

用途:啟用無介面模式

引數:--disable-popup-blocking

用途:禁用彈出攔截

無介面模式示例:

1

from selenium import

webdriver

2 chrome_options =webdriver.chromeoptions()3#

啟用無介面模式

4 chrome_options.add_argument('

--headless')

5 driver = webdriver.chrome(chrome_options=chrome_options)

6 url = "

file:///e:/log/index.html"7

driver.get(url)

8 keys =

9for i in range(1,13):10#

使用format代替%s

11 key = driver.find_element_by_xpath('

//*[@id="statisticstable"]/thead/tr/th/div

'.format(id =i)).text

1213

14 valuestr = driver.find_element_by_xpath('

//*[@id="statisticstable"]/tbody[2]/tr

').text

15 values = valuestr.split("")

16#字典推導式,in後面必須加元祖或zip的迭代器等

1718 dict =

19print

(dict)

2021 driver.close()

參考:     (無介面瀏覽)

(chrome啟動引數)

(format代替%s等)   

1

def open(browser="

chrome

",url="

"):2 options =webdriver.chromeoptions()

3 options.add_experimental_option("

excludeswitches

",["

ignore-certificate-errors"])

4 option.add_argument('

') #

設定成使用者自己的資料目錄

5 driver = eval("

webdriver.%s()

" %browser)

6driver.get(url)

7 driver.find_element_by_id("

txtusername

").send_keys("

fanyw")

8 driver.find_element_by_id("

txtpwd

").send_keys("

1234567b")

9 sleep(1)10#

driver.find_element_by_id("btnlogin").click()

11print("

i was at the chrome %s

" %ctime())

1213

14def

startfirefoxwithspecificlocation():

15"""

"""16 binary = firefoxbinary('

d:\program files\mozilla firefox\\firefox.exe')

17 driver = webdriver.firefox(firefox_binary=binary)

18 driver.get("

")

Chrome啟動引數大全

1218 use first display as internal 使用 ash host window bounds中的第乙個顯示作為內部顯示。這是用於在linux桌面上進行除錯。1219 use gl 選擇gpu程序應該使用的gl實現。選項包括 桌面 使用者安裝的任何桌面opengl linu...

Chrome無介面瀏覽模式與自定義外掛程式載入問題

環境 python 3.5.x selenium 3.4.3 chromedriver 2.30 chrome 60 beta或chromium canary 61 win10 chrome啟用無介面瀏覽模式時,自定義外掛程式是沒法載入的,會報以下錯誤 selenium.common.excepti...

Chrome 靜默列印及其它啟動引數

此方法只能在客戶端設定,瀏覽器本身不提供許可權通過js控制印表機 在位址列敲 about flags 開啟設定介面 停用 無此選項則跳過 enable print preview registration promos windows,linux,chrome os chrome快捷方式增加 這樣就...