Python Webdriver:使用代码创建配置文件

huangapple go评论59阅读模式
英文:

Python Webdriver : Profile Creation Using Code

问题

有没有办法使用代码创建浏览器配置文件?Chrome、Gecko、Brave、Edge或其他任何浏览器都可以。想要使用代码创建配置文件以节省时间。我尝试在互联网上查找,但找不到任何解决方案,谢谢。

我尝试在GitHub和Stack Overflow上查找,但没有运气。也尝试了ChatGPT。

英文:

is there any way we can create browser profiles using code? chrome,gecko , brave , edge or any other. want to create profiles using code to save time. i tried looking over internet but couldn't find any solution , thanks

i tried looking over github and stackoverflow but no luck. tried chatgpt too

答案1

得分: 0

你可以使用以下代码创建Chrome配置文件,只需指定要保存配置文件的路径和配置文件的名称:

import selenium.webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.chrome.options import Options
import os

chrome_options = selenium.webdriver.ChromeOptions()
chrome_options.add_argument('start-maximized')
chrome_options.add_argument("user-data-dir=" + os.path.abspath('Profiles/Jason')) # 指定要保存创建的配置文件的位置
chrome_options.add_argument("--disable-plugins")
chrome_options.add_argument("--disable-extensions-file-access-check")
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
driver = selenium.webdriver.Chrome(chrome_options=chrome_options)
# 在这里添加你的代码

请注意,这段代码用于创建一个已配置的Chrome浏览器实例,其中包括指定的配置文件路径和名称。

英文:

You can create chrome profiles using the code below, just specify the path you want profiles save in & the name of profile :

import selenium.webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.chrome.options import Options
import os

chrome_options = selenium.webdriver.ChromeOptions()
chrome_options.add_argument('start-maximized')
chrome_options.add_argument("user-data-dir="+os.path.abspath('Profiles/Jason')) # Put were you want save created profiles
chrome_options.add_argument("--disable-plugins")
chrome_options.add_argument("--disable-extensions-file-access-check")
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
driver = selenium.webdriver.Chrome(chrome_options=chrome_options)   
# Your code here

huangapple
  • 本文由 发表于 2023年6月15日 21:46:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76483149.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定