1

Authentication window snap如何处理使用硒与Python的Windows身份验证弹出?

已经尝试过下面的方法,

1)https://username:[email protected]

我的用户名包含 '\' 这就是为什么它给问题。

2)切换到警报系统 在此我得到“不警示”异常

请在这种情况下帮助/推荐任何其他方法来处理与蟒蛇windows身份验证...

+0

您应该尝试对网址进行反斜杠编码。否则,你的网站似乎不希望你自动化或网上刮它 –

+0

这些有帮助吗? http://stackoverflow.com/questions/10395462/handling-browser-authentication-using-selenium?lq=1; http://stackoverflow.com/questions/24304752/how-to-handle-authentication-popup-with-selenium-webdriver-using-java? – nullpointer

+0

通过使用'\'的编码值,它的工作.... – Sankalp

回答

2

安装win32com.client然后尝试下面的代码

from selenium import webdriver 
import time 
import win32com.client 

driver=webdriver.Firefox() 
driver.maximize_window() 
driver.get('url') 
shell = win32com.client.Dispatch("WScript.Shell") 
shell.Sendkeys("username") 
shell.Sendkeys("{TAB}") 
shell.Sendkeys("password") 
shell.Sendkeys("{ENTER}") 
time.sleep(5) 
driver.quit() 
+0

只是要注意你不要点击Windows中的任何其他地方,因为文本将在你有光标的地方发送! –