1. 程式人生 > 其它 >selenium 新增特殊配置(如不完整 希望各位大神評論告訴我)

selenium 新增特殊配置(如不完整 希望各位大神評論告訴我)

#新增特殊配置
options=webdriver.ChromeOptions()
#設定預設編碼為utf-8,也就是中文
options.add_argument('lang=zh_CN.UTF-8')
#模擬androidQQ瀏覽器
options.add_argument(
'user-agent="MQQBrowser/26Mozilla/5.0(Linux;U;Android2.3.7;zh-cn;MB200Build/GRJ22;CyanogenMod-7)AppleWebKit/533.1(KHTML,likeGecko)Version/4.0MobileSafari/533.1"')
#禁止硬體加速
options.add_argument('--disable-gpu') #取消沙盒模式 options.add_argument('--no-sandbox') #禁止彈窗廣告 options.add_argument('--disable-popup-blocking') #最大介面 options.add_argument('--window-size=1920,1080') #去掉反扒標誌 options.add_experimental_option('excludeSwitches',['enable-automation']) #此方法針對V78版本及以上有效,同時可以解決部分網站白屏的問題。
options.add_experimental_option('useAutomationExtension',False) ##大量渲染時候寫入/tmp而非/dev/shm options.add_argument("-–disable-dev-shm-usage") desired_capabilities=DesiredCapabilities.CHROME desired_capabilities["pageLoadStrategy"]="none" #忽略證書錯誤(實操沒卵用) options.add_argument('--ignore-certificate-errors') self.bro
=webdriver.Chrome(executable_path='../Chrome_path/chromedriver.exe',options=options) driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", { "source": """ Object.defineProperty(navigator, 'webdriver', { get: () => undefined }) """ })