我需要从表中获取一个值,该值在JavaScript之后可见。 我的程序需要登录到该网站(已解决),然后需要从表中获取数据
https://imgur.com/a/uCYXK18“表格中的数据”(需要突出显示黄色)
我尝试了HtmlAgilityPack,在其中我发现这些数据已用JavaScript加载
https://imgur.com/a/fpxntZG“ HtmlAgilityPack”
代码:
//logging into website
var loginAddress = "http://myweb/users/login/";
var loginData = new NameValueCollection
{
{ "username", "admin" },
{ "password", "*****" }
};
var client = new CookieAwareWebClient();
client.Login(loginAddress, loginData);
//getting website after login
string htmlSource = client.DownloadString("http://myweb/");
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(htmlSource);
//website after login
编辑-----------------------------------
//getting table
var table = doc.GetElementbyId("miner-table-details");
do
{
htmlSource = client.DownloadString("http://myweb/");
doc.LoadHtml(htmlSource);
table = doc.GetElementbyId("miner-table-details");
Console.WriteLine("Loading..");
} while (!table.HasChildNodes);
//if table has ChildNodes it will end loop and I could possibly get data from table
Console.WriteLine("Found");