【问题标题】:Is there a way that selenium can input my username and password into the browser's prompt? [duplicate]selenium 有没有办法将我的用户名和密码输入到浏览器的提示符中? [复制]
【发布时间】:2019-04-11 01:19:51
【问题描述】:

我正在尝试抓取一个请求我的用户名和密码的网站。我找到了一种使用 selenium 的方法,但我必须手动输入我的凭据。 我希望 chrome 驱动程序自动输入我的凭据并开始工作。

我尝试使用选择功能和发送键,但似乎没有任何效果。 我认为原因是提示看起来像 localhost 提示,它不在网页本身中

url = "http://www.incidentpage.net/members/ticker_content.js"

# create a new Chrome session (NEED TO MANUALY INPUT CREDENTIALS)
# Username is 'Jack Bibi' 
# Password is 'IPN545'
driver = webdriver.Chrome('./chromedriver')
driver.implicitly_wait(3)
driver.get(url)

这是链接拉出的屏幕截图。

【问题讨论】:

    标签: python-3.x selenium-webdriver


    【解决方案1】:

    这看起来是标准的 HTTP 身份验证,而不是需要通过 Selenium 提交的登录表单。尝试使用 http://user:pass@host... 的 HTTP Auth 模式,如下所示:

    driver.get('http://{un}:{pw}@incidentpage.net/members/ticker_content.js'.format(un='foo', pw='bar'))
    

    要了解有关 HTTP 身份验证的更多信息,请查看 Mozilla 的 docs

    另一个SO post 也是相关的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-27
      • 1970-01-01
      • 1970-01-01
      • 2012-08-11
      • 1970-01-01
      • 2020-12-04
      • 2015-11-05
      • 2011-10-24
      相关资源
      最近更新 更多