1

I am trying to get data from a website an C#:

https://secure.lni.wa.gov/verify/Detail.aspx?LIC=1CALLCC871KC

It looks like this website gets the data from an ajax call after the page loads. When I call this code:

    using (var client = new WebClient())
    {
        return client.DownloadString(URL);
    }

It gets the base HTML but does not process the ajax call and fill in the data. Is there a way to get the final page after rendering from code?

Bitco Software
  • 405
  • 1
  • 5
  • 15
  • possible duplicate of [Get html that is generated via AJAX in webclient](http://stackoverflow.com/questions/2950821/get-html-that-is-generated-via-ajax-in-webclient) – Backs Aug 11 '15 at 07:22
  • are you using the url of the website or the url accessed by the ajax call? – yohannist Aug 11 '15 at 08:00

1 Answers1

1

Instead of parsing that html content you can directly call the GetBusinessDetails method to get a json result back.

string URL = "https://secure.lni.wa.gov/verify/Controller.aspx/GetBusinessDetails";

using (var client = new WebClient())
{
    client.Headers["Content-Type"] = "application/json; charset=UTF-8";
    var json =  client.UploadString(URL, JsonConvert.SerializeObject(new { License = "1CALLCC871KC", Ubi ="", IrlVilationId="", IsSecured="" }));

    dynamic response = JsonConvert.DeserializeObject(json);
    Console.WriteLine(response.d.ReturnValue.Contractor.BusinessName.ToString());
}

JsonConvert.SerializeObject and JsonConvert.DeserializeObject are methods in Json.Net library

Eser
  • 12,346
  • 1
  • 22
  • 32