HTTPS网站上的Selenium Python身份验证浏览器登录弹出对话框 [英] Selenium Python Authenticating browser login pupup dialog at a HTTPS website

查看:348
本文介绍了HTTPS网站上的Selenium Python身份验证浏览器登录弹出对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计,

我正在研究一个抓取脚本,该脚本每天运行一次,需要重新验证我的帐户.

首先我必须登录,然后只有我才能看到该页面.像正常的页面登录和抓取一样,这将不起作用(请阅读文章,并使用大多数博客和论坛上建议的以下代码).

这是一个https网站.

URL: https://www2.somewebsite.com/mypage.php

现在我有了以下代码:

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)

但是上面的代码没有填写弹出框字段中的数据,也没有单击登录".

会有什么问题?

我确实在>如何提交HTTP中尝试了此操作使用Selenium python绑定Webdriver进行身份验证

但也没有成功.

profile = webdriver.FirefoxProfile()
profile.set_preference('network.http.phishy-userpass-length', 255)
driver = webdriver.Firefox(firefox_profile=profile)
driver.get("https://username:password@somewebsite.com/")

解决方案

这对我有用:

driver = webdriver.Firefox()
driver.get("https://username:password@testwebsite.com/testpage.html")
driver.implicitly_wait(30)

Folks,

I am working on a scraping script which is running once a day where I need to re-authenticate my account.

First I have to login and then only I can see the page. Like normal page login and scrapping this won't work (read in articles and used the code below as suggested on most of the blogs and forumns) This still doesn't work.

It's an https website.

URL: https://www2.somewebsite.com/mypage.php

Now I have this code:

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)

However the above code doesn't fills in the data in popup box fields, not clicks on Login.

What would be the issue?

EDIT 1:

I did tried this from How to Submit HTTP authentication with Selenium python-binding webdriver

But no success either.

profile = webdriver.FirefoxProfile()
profile.set_preference('network.http.phishy-userpass-length', 255)
driver = webdriver.Firefox(firefox_profile=profile)
driver.get("https://username:password@somewebsite.com/")

解决方案

This works for me:

driver = webdriver.Firefox()
driver.get("https://username:password@testwebsite.com/testpage.html")
driver.implicitly_wait(30)

这篇关于HTTPS网站上的Selenium Python身份验证浏览器登录弹出对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆