从加载动态数据的页面获取C#中的HTML [英] Get HTML in C# from page that Loads Dynamic Data

查看:417
本文介绍了从加载动态数据的页面获取C#中的HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从网站上获取C#数据:

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

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

页面加载后,似乎该网站从ajax调用中获取了数据.当我调用此代码时:

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);
    }

它获取基本HTML,但不处理ajax调用并填写数据.有没有办法从代码渲染后获得最终页面?

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?

推荐答案

您可以直接调用 GetBusinessDetails 方法来获取json结果,而不用解析该html内容.

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.SerializeObjectJsonConvert.DeserializeObject Json.Net

这篇关于从加载动态数据的页面获取C#中的HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆