首页 > 解决方案 > 使用 AngleSharp 向 Microsoft 进行身份验证

问题描述

我正在尝试使用 AngleSharp 对 login.microsoftonline.com 进行身份验证,以便我可以使用它们作为 SSO 提供程序从站点收集数据。

到目前为止我得到的代码: -

var config = Configuration.Default
    .WithJs()
    .WithCss()
    .WithDefaultLoader()
    .WithDefaultCookies();

IBrowsingContext browsingContext = BrowsingContext.New(config);

browsingContext.OpenAsync(@"http://login.microsoftonline.com/").Wait();

(browsingContext.Active.QuerySelector("input[name = 'loginfmt']") as IHtmlInputElement).Value = @"username";
(browsingContext.Active.QuerySelector("form") as IHtmlFormElement).SubmitAsync().Wait();
(browsingContext.Active.QuerySelector("input[name = 'passwd']") as IHtmlInputElement).Value = @"password";
(browsingContext.Active.QuerySelector("form") as IHtmlFormElement).SubmitAsync().Wait();

// Further code then using the cookie(s) once authenticated...

本质上,'input[name = 'loginfmt']' 使用此代码解析为无,尽管在浏览器中工作正常......在检查“活动”文档(及其子文档)后,它似乎只是充满了JavaScript并且在任何地方都看不到表单..?

标签: c#web-scrapinganglesharp

解决方案


推荐阅读