Psy*_*oic 6 python parsing adfs
我需要解析被ADFS服务隐藏的站点。
并为此进行身份验证。
有进入的选项吗?
我可以看到,大多数针对后端应用程序或“系统用户”(带有app_id,app_secret)的解决方案。就我而言,我只能使用登录名和密码才能使用它。
问题的示例:在“ chrome我打开”中www.example.com,它将重定向到https://login.microsoftonline.com/,然后https://federation-sts.example.com/adfs/ls/?blabla使用登录名和密码形式。
以及如何访问它python3?
ADFS uses complicated redirection and CSRF protection techniques. Thus, it is better to use a browser automation tool to perform the authentication and parse the webpage afterwards. I recommend the selenium toolkit with python bindings. Here is a working example:
from selenium import webdriver
def MS_login(usrname, passwd):  # call this with username and password
    driver = webdriver.Edge()   # change to your browser (supporting Firefox, Chrome, ...)
    driver.delete_all_cookies() # clean up the prior login sessions
    driver.get('https://login.microsoftonline.com/') # change the url to your website
    time.sleep(5) # wait for redirection and rendering
    driver.find_element_by_xpath("//input[@name='loginfmt'").send_keys(usrname)
    driver.find_element_by_xpath("//input[@type='submit']").click()
    time.sleep(5)
    driver.find_element_by_xpath("//input[@name='passwd'").send_keys(passwd)
    driver.find_element_by_xpath("//input[@name='KMSI' and @type='checkbox'").click()
    driver.find_element_by_xpath("//input[@type='submit']").click()
    time.sleep(5)
    driver.find_element_by_xpath("//input[@type='submit']").click()
    # Successfully login
    # parse the site ...
    driver.close() # close the browser
    return driver
Run Code Online (Sandbox Code Playgroud)
This script calls Microsoft Edge to open the website. It injects the username and password to the correct DOM elements and then let the browser to handle the rest. It has been tested on the webpage "https://login.microsoftonline.com". You may need to modify it to suit your website.
|   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           1305 次  |  
        
|   最近记录:  |