public async Task Execute(ICrawlingContext context) { var doc = await CrawlingHelper.GetHtmlDocument(context.Client, Url); CrawlingHelper.SetEventParams(context, doc); var hidStepGuid = doc.GetElementbyId("hidStepGuid")?.GetAttributeValue("value", null); context.Set("hidStepGuid", hidStepGuid); var response = await context.Client.PostAsync(Url, new FormUrlEncodedContent(BuildFormData(context))); string redirectFile = null; try { redirectFile = response.Headers.Location?.Segments.LastOrDefault(); } catch (Exception) { //ignore } EnsureRedirectFile(redirectFile); }
public static void SetEventParams(ICrawlingContext context, HtmlDocument document) { context.Set("viewState", document.GetElementbyId("__VIEWSTATE")?.GetAttributeValue("value", null)); context.Set("eventValidation", document.GetElementbyId("__EVENTVALIDATION")?.GetAttributeValue("value", null)); }