Python 如何使用Selenium打开带有我的书签和设置的浏览器实例?
我使用brave浏览器作为默认浏览器,但我想知道,当我运行代码时,是否可以打开我的常规浏览器配置文件,而不是新实例,因为它没有我所有的书签和密码 提前谢谢Python 如何使用Selenium打开带有我的书签和设置的浏览器实例?,python,selenium,Python,Selenium,我使用brave浏览器作为默认浏览器,但我想知道,当我运行代码时,是否可以打开我的常规浏览器配置文件,而不是新实例,因为它没有我所有的书签和密码 提前谢谢 from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
import datetime
day = datetime.datetime.now()
dag = day.weekday()
def Testing():
if dag >= 5:
return Weekend()
else:
return Weekday()
def Weekend():
options = Options()
options.add_argument("--window-size=1920,1080")
## options.add_argument("/Users/vadim/Library/Application Support/BraveSoftware/Brave-Browser")
options.binary_location = '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser'
driver_path = '/usr/local/bin/chromedriver'
driver = webdriver.Chrome(options=options, executable_path=driver_path)
driver.get('https://outlook.live.com/mail/0/inbox')
Outlook_Aanmelden = driver.find_element_by_xpath('/html/body/header/div/aside/div/nav/ul/li[2]/a')
Outlook_Aanmelden.click()
Email_Field = driver.find_element_by_xpath('//*[@id="i0116"]')
Email_Field.send_keys('@live.com')
Outlook_Volgende = driver.find_element_by_xpath('//*[@id="idSIButton9"]')
Outlook_Volgende.click()
time.sleep(0.5)
Password_Field = driver.find_element_by_xpath('//*[@id="i0118"]')
Password_Field.send_keys('pass')
Password_Field.send_keys(Keys.ENTER)
Inlog_Outlook = driver.find_element_by_xpath('//*[@id="idSIButton9"]')
Inlog_Outlook.click()
driver.execute_script("window.open('https://youtube.com');")
def Weekday():
options = Options()
options.add_argument("--window-size=1920,1080")
## options.add_argument("/Users/vadim/Library/Application Support/BraveSoftware/Brave-Browser")
options.binary_location = '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser'
driver_path = '/usr/local/bin/chromedriver'
driver = webdriver.Chrome(options=options, executable_path=driver_path)
driver.get('https://outlook.live.com/mail/0/inbox')
Outlook_Aanmelden = driver.find_element_by_xpath('/html/body/header/div/aside/div/nav/ul/li[2]/a')
Outlook_Aanmelden.click()
Email_Field = driver.find_element_by_xpath('//*[@id="i0116"]')
Email_Field.send_keys('@live.com')
Outlook_Volgende = driver.find_element_by_xpath('//*[@id="idSIButton9"]')
Outlook_Volgende.click()
time.sleep(0.5)
Password_Field = driver.find_element_by_xpath('//*[@id="i0118"]')
Password_Field.send_keys('pass')
Password_Field.send_keys(Keys.ENTER)
Inlog_Outlook = driver.find_element_by_xpath('//*[@id="idSIButton9"]')
Inlog_Outlook.click()
driver.execute_script("window.open('https://youtube.com');")
Testing()
所以,是的,这个问题已经存在了一段时间了,现在还没有找到任何人知道解决方案,也许你可以帮我解决吗?你需要用用户配置文件加载你的
chrome
,就像这样。假设它是铬合金而不是勇敢的
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('user-data-dir=<path to chrome profile>')
browser = webdriver.Chrome(chrome_options=chrome_options)
从selenium导入webdriver
chrome\u options=webdriver.ChromeOptions()
chrome_选项。添加_参数('user-data-dir='))
浏览器=webdriver.Chrome(Chrome\u选项=Chrome\u选项)
Chrome默认配置文件文件夹的位置因平台而异。地点如下:
Windows 7, 8.1, and 10: C:\Users\<username>\AppData\Local\Google\Chrome\User Data\Default
Mac OS X El Capitan: Users/<username>/Library/Application Support/Google/Chrome/Default
Linux: /home/<username>/.config/google-chrome/default
windows7、8.1和10:C:\Users\\AppData\Local\Google\Chrome\User Data\Default
Mac OS X El Capitan:用户//库/应用程序支持/Google/Chrome/Default
Linux:/home/.config/google chrome/default
我的第一个问题是,你为什么想要书签?和保存的密码?我基本上想用我的大学时间表、邮件等自动完成我早上打开浏览器的路线。我想在那里放上书签和其他东西,这样我可以在检查了那些主要网站后继续浏览。Selenium可能不是你想要的工具。我不熟悉使用Brave浏览器,但chrome(您使用的是chrome驱动程序)允许您指定要启动的用户配置文件。