Selenium Python身份验证浏览器登录pupup对话框

2024-10-04 05:31:05 发布

您现在位置:Python中文网/ 问答频道 /正文

各位

我正在编写一个每天运行一次的脚本,在那里我需要重新验证我的帐户。在

首先我必须登录,然后我才能看到页面。就像普通的页面登录和取消一样,这是行不通的(阅读文章,并按照大多数博客和论坛的建议使用下面的代码),这仍然不起作用。在

这是一个https网站。在

网址:https://www2.somewebsite.com/mypage.php

enter image description hereenter image description here

现在我有了这个代码:

def InitializeBrowser():
    browser = webdriver.Firefox()
    browser.set_window_size(1120, 550)
    return browser

def CheckTest(request):
    browser = InitializeBrowser()
    data = browser.get("https://gitroix:Ju2R4kmb@www2.sfmx.org/camera.php")
    alert = browser.switch_to_alert()
    alert.accept()
    browser.close()
    return HttpResponse(data.contents)

但是,上面的代码不会在弹出框字段中填充数据,而不会在登录时单击。在

会有什么问题?在

编辑1:

我确实从How to Submit HTTP authentication with Selenium python-binding webdriver尝试过这个

但也没有成功。在

^{pr2}$

Tags: to代码httpsbrowser脚本datareturndef