Selenium控制Firefox禁止弹出窗口问题

对于不好破解API的网站,爬取数据只好通过selenium来客户端模拟,selenium有很多坑,实在是一个接着一个,而且相关好的介绍文档比较少,最近selenium模拟登陆总遇到弹出询问窗口的问题,如下图所示:

image

需要反复点击很麻烦,查了很多文档,最后总结出以下的方法禁止弹出窗口:


option = webdriver.FirefoxProfile()

option.set_preference("dom.webnotifications.enabled",False)

browser = webdriver.Firefox(option)

原理是设置firefox的about:config页面,如下图:

image

代码中提供了selenium中的实现,供大家参考

你可能感兴趣的:(Selenium控制Firefox禁止弹出窗口问题)