title: How to download a file from a website where i have to log in and where the download starts with a javascript form submit?
body: <p>I have to download a file a day from a website. 
  I have to log in, go to the download page, insert strings in a form, then click on an "Export" button which starts a js script which submits the form and starts the download. I tried pretty much everything, understood that JS couldn't be handled by the HtmlAgilityPack. </p>
  
  <p>I used ScrapySharp to simulate a web browser. I can log in, go to the export page, click on the button and get the response, but can't handle the download.</p>
  
  <p>Here's my code : </p>
  
  <pre><code>public class GetCSVFileTask : BaseTask
  {
      ScrapingBrowser Browser;
      public GetCSVFileTask(IStateMachine StateMachine, ITraceEngine Trace, ILogEngine Log)
          : base(StateMachine, Trace, Log)
      {
          this.Log = Log;
          this.Trace = Trace;
          this.stateMachine = StateMachine;
      }
  
      public void Process()
      {
          try
          {
              Init();
              Login();
              DownloadCSV();
          }
          catch (Exception ex)
          {
              Log.Write(LogLevel.Error, string.Format(CultureInfo.InvariantCulture, "Exception: {0}.", ex.ToString()));
          }
      }
  
      private void Init()
      {
          Browser = new ScrapingBrowser();
          Browser.AllowAutoRedirect = true;
          Browser.AllowMetaRedirect = true;
          Browser.AutoDetectCharsetEncoding = true;
          Browser.AutoDownloadPagesResources = true;
      }
      private void Login()
      {
          var test = new Uri(ConfigurationManager.AppSettings.Get("LoginURL"));
          WebPage LoginPage = Browser.NavigateToPage(test);
  
          var AuthForm = GetAuthForm(LoginPage, Browser);
  
          AuthForm["Email"] = ConfigurationManager.AppSettings.Get("Login");
          AuthForm["Password"] = ConfigurationManager.AppSettings.Get("Password");
  
          AuthForm.Submit();
      }
  
      private void DownloadCSV()
      {
          WebPage ExportPage = Browser.NavigateToPage(new Uri(ConfigurationManager.AppSettings.Get("ExportURL")));
  
          PageWebForm DLForm = GetDlForm(ExportPage, Browser);
  
          WebPage test = DLForm.Submit();
      }
  
      private PageWebForm GetAuthForm(WebPage loginPage, ScrapingBrowser browser)
      {
          //temp[0] = logout form
          //temp[1] = login form
          var temp = (from n in loginPage.Encoding.GetString(loginPage.RawResponse.Body).ToHtmlNode().Descendants("form")
                      select n).ToList();
  
          return new PageWebForm(temp[1], browser);
      }
      private PageWebForm GetDlForm(WebPage exportPage, ScrapingBrowser browser)
      {
          //temp[0] = logout form
          //temp[1] = download form
          return GetAuthForm(exportPage, browser);
      }
  }
  </code></pre>
  
  <p>The issue I have at the moment is that I don't know how to "catch" the file download and download it in a local folder</p>
  
  <p>Sorry for my bad english, i'm french and new in the developer world :)</p>