推荐
关注
TOP
Message

selenium 添加特殊配置(如不完整 希望各位大神评论告诉我)

options 常用配置

点击展开
#添加特殊配置
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'])
#禁止Chrome弹出提示窗
options.add_argument("--disable-popup-blocking")
#此方法针对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')
#保存浏览历史下次读取直接读取里面的内容
dir_path = os.getcwd()
options.add_argument(f'user-data-dir={dir_path}/userData')
self.bro=webdriver.Chrome(executable_path=f'{dir_path}/Chrome_path/chromedriver.exe',options=options)
# 将window.navigator.webdriver属性变为undefined 防止检测
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": """
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
})
"""
})

selenium 安装驱动

安装

pip install webdriver-manager
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
posted @   始識  阅读(441)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示