因为某种原因,chrome的
add_extension
添加扩展名
不工作(目前)这里是我的解决办法,添加扩展到火狐。
-
通过创建新的firefox配置文件
right click windows start button > run > firefox.exe -P
-
然后添加任何你想要的扩展,ublock,adblock plus等等
-
profile = selenium.webdriver.FirefoxProfile("C:/test")
browser = selenium.webdriver.Firefox(firefox_profile=profile, options=ops)
显然
profile.add_extension()
不是此解决方案的必备组件
更新!-添加了chrome配置文件
为了对称起见,我更新了chrome示例代码以使用chrome配置文件,而不是调用
.crx
直接。
-
-
导航到
C:\Users\User\AppData\Local\Google\Chrome
User Data
chrome_profile
:
ops = options()
ops.add_argument("--headless") if hide is True else ops.add_argument("--head")
ops.add_argument('user-data-dir=chrome_profile')
ops.add_argument('--profile-directory=Default')
ops.add_argument("--incognito")
browser = selenium.webdriver.Chrome(executable_path='chromedriver.exe', options=ops, desired_capabilities={'binary_location': 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe'})