我正在工作中自动化一些任务,我需要使用Selenium来获取内部网站上更新的数据。
我可以从我的帐户打开网站并在边缘浏览器中查看这些数据,无需任何身份验证,
但是,当我使用EdgeDriver打开相同的网站时,每次运行代码时都会被提示输入MFA。
我不能自动使用MFA,因为我得用我的手机,
是否可以在EdgeDriver中使用与边缘浏览器相同的凭据?还是直接在selenium中使用边缘浏览器?
谢谢,
Python代码如下:
from selenium import webdriver
from time import sleep
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.edge.options import Options
from selenium.webdriver.support.wait import WebDriverWait
import schedule
import time
from random import randint
def job():
while True:
print("started health checkin")
# Instantiate the webdriver with the executable location of MS Edge
browser = webdriver.Edge(r"C:\msedgedriver.exe")
# Simply just open a new Edge browser and go to lambdatest.com
sleep(2)
#browser.maximize_window()
sleep(2)
browser.get('https://xxxxxxxxxxxxxxxxxxxxxxxxx')
try:
sleep(3)
myElem_2 = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH, '/html/body/div[3]/div[3]/div/ng-component/pbi-menu/button[3]')))
# Entering the email address
sleep(3)
myElem_2.click()
except TimeoutException:
print("No element found")
sleep(5)
browser.close()
def day_job():
sleep(randint(10,1000))
job()
job()
print("starting daily timer")
schedule.every().day.at("08:00").do(day_job)
while True:
schedule.run_pending()
time.sleep(60) # wait one minute
发布于 2022-10-07 15:20:51
实际上,您需要的是使用Chrome:https://stackoverflow.com/a/31063104/7058266的前一个答案的边缘版本,用于这个问题:How to load default profile in Chrome using Python Selenium Webdriver?
如果您已经这样做了,为了避免再次执行2因子auth,请重用配置文件。
下面是如何使其适用于Edge的方法:
from selenium import webdriver
from selenium.webdriver.edge.options import Options
options = Options()
options.add_argument("user-data-dir=PATH_TO_YOUR_EDGE_PROFILE")
driver = webdriver.Edge(options=options)
然后做你所做的一切。您可能应该在启动之前复制您的user-data-dir
,以防Selenium进行不必要的更改。
https://stackoverflow.com/questions/73993262
复制