selenium 定製啓動chrome的參數
設置代理. 禁止圖片加載 修改ua
https://blog.csdn.net/vinson0526/article/details/51850929python
1.配置chrome以手機模擬器
https://blog.csdn.net/u013948858/article/details/81123951web
from selenium import webdriver mobile_emulation = { "deviceName": "Nexus 5" } chrome_options = webdriver.ChromeOptions() chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) # 這裏看清楚了,不是add_argument driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub',desired_capabilities = chrome_options.to_capabilities()) #==== from selenium import webdriver from selenium.webdriver.chrome.options import Options mobile_emulation = { "deviceMetrics": { "width": 360, "height": 640, "pixelRatio": 3.0 }, "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19" } chrome_options = Options() chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) # 這裏看清楚了,不是add_argument driver = webdriver.Chrome(chrome_options = chrome_options) # 這裏的chrome_options 建議都使用 desired_capabilities ,應爲在Grid分佈式中比較方便
2.取消顯示 收到自動化軟件的控制 / 靜默方式運行chrome
from selenium import webdriver # 加啓動配置 option = webdriver.ChromeOptions() option.add_argument('disable-infobars') #return webdriver.Chrome(chrome_options = option,desired_capabilities = None) # 打開chrome瀏覽器 driver = webdriver.Chrome(chrome_options=option) driver.get("https://www.baidu.com") from selenium import webdriver # 加啓動配置 option = webdriver.ChromeOptions() option.add_argument('headless') # 打開chrome瀏覽器 driver = webdriver.Chrome(chrome_options=option) driver.get("https://www.baidu.com")