首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在Selenium中持久化Tampermonkey脚本?

如何在Selenium中持久化Tampermonkey脚本?
EN

Stack Overflow用户
提问于 2019-01-23 22:31:05
回答 1查看 1.9K关注 0票数 2

我想在页面加载之前运行一个JS脚本,所以我把它放在了TAMPER猴子中。但在驱动程序关闭后,脚本不会持续存在。如果我再次运行代码,保存的脚本将不复存在。这是在python中运行selenium的代码。

代码语言:javascript
运行
复制
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager

opts = Options()
opts.add_extension("tampermonkey extension.zip")
driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=opts)
driver.get("url")
# Add the JS script in Tampermonkey in the browser manually
driver.close()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-23 22:48:59

要在驱动程序“回收”之后持久化任何扩展或特定设置,您唯一的选择就是拥有一个自定义配置文件,并告诉selenium使用该配置文件。

在Chrome中有一个很好的答案:How to load default profile in chrome using Python Selenium Webdriver?

在火狐中,Selenium:https://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.firefox.webdriver直接支持,请参见webdriver.Firefox()构造函数https://selenium-python.readthedocs.io/api.html#selenium.webdriver.firefox.firefox_profile.FirefoxProfile的第一个参数

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54329519

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档