Skip to main content
 首页 » 编程设计

python之如何在 chromedriver 中屏蔽视频

2025年02月15日33daizhj

当我使用 selenium 抓取“twitter.com”时,我无法阻止自动播放的视频剪辑。如何阻止视频剪辑以减少 chromedriver 中的内存负担。

下面是代码

chromeOptions = webdriver.ChromeOptions() 
prefs = {"profile.managed_default_content_settings.images" : 2} 
chromeOptions.add_experimental_option("prefs",prefs) 
browser = webdriver.Chrome(executable_path =    
'C:/Users/aa/Downloads/chromedriver/chromedriver.exe',  
chrome_options=chromeOptions) 

请您参考如下方法:

在 Twitter 站点中,转到“配置文件和设置”,然后在内容设置中取消选中 Video autoplay 复选框。如果需要,您可以在 Selenium 的帮助下自动执行此操作。