htmllagilitypack -如何在函数{}中获得Innerhtml值



我正在尝试解析一个网站,其中有以下html行

<script type="text/javascript">
$(document).ready(function() {
set_rate()
});
function set_rate() {
var rate_f = "1";
$('#rate_c').html("1.10");
$('#rate_g').html("7.00");
$('#time').html("23/08/2021 Evening 02:31 PM");
}

我不知道html,所以我迷失在指向HtmlAgilityPack正确的节点。

我试图获得$('#rate_c').html("1.10");值1.10,$('#rate_g').html("7.00");值7.00和$('#time').html("23/08/2021 Evening 02:31 PM");value 23/08/2021晚上02:31 PM

我没有试图获得值函数运行JavaScript后给出,幸运的是我的html有我正在寻找的值。

根据您在聊天中的评论,您可以尝试这样做:

Dim result = New With {.rate_c = "", .rate_g = "", .time = ""}
Dim doc As New HtmlAgilityPack.HtmlDocument
doc.Load("C:Temptest.html")
Dim scriptNodes = doc.DocumentNode.SelectNodes("//script")
For Each scriptNode In scriptNodes
If scriptNode.InnerHtml.Contains("$('#rate_c').html(") Then
result.rate_c = scriptNode.InnerHtml.Substring(scriptNode.InnerHtml.IndexOf("$('#rate_c').html(") + "$('#rate_c').html(".Length + 1)
result.rate_c = result.rate_c.Substring(0, result.rate_c.IndexOf(""""))
End If
If scriptNode.InnerHtml.Contains("$('#rate_g').html(") Then
result.rate_g = scriptNode.InnerHtml.Substring(scriptNode.InnerHtml.IndexOf("$('#rate_g').html(") + "$('#rate_g').html(".Length + 1)
result.rate_g = result.rate_g.Substring(0, result.rate_g.IndexOf(""""))
End If
'--- ... similarly get other values here ...
Next
'-- lets see what we got!
MessageBox.Show($"rate_c={ result.rate_c}    rate_g={result.rate_g}")

最新更新