正如試圖抓住每個標籤發生的每個InnerText並將其添加到列表中的標題所簡述的那樣。這裏是我的代碼爲藏漢我的html:c#HtmlAgilityPack,如何抓住特定標籤的所有出現的InnerText?
HTML的身體:
<body cz-shortcut-listen="true">
{"draw":1,"recordsTotal":9437,"recordsFiltered":9437,"data":[["
<a target="\"_blank\"" href="\"\/id\/115739257\"">AK-47 | Aquamarine Revenge (Factory New)<\/a>","</a>
<a target="\"_blank\""href="\"\/id\/115739257\"">33.87<\/a>","</a>
<a target="\"_blank\"" href="\"\/id\/115739257\"">34.53<\/a>","</a>
<a target="\"_blank\"" href="\"https:\/\/track.steamanalyst.com\/730\/115739257\/all\"">25.9<\/a>","</a>
<a target="\"_blank\"" href="\"\/id\/115739257\"">164<\/a>","</a>
<a target="\"_blank\"" href="\"\/id\/115739257\"">-0.16<\/a>","</a>
<a target="\"_blank\"" href="\"\/id\/115739257\"">2.10945<\/a>"],["</a>
<a target="\"_blank\"" href="\"\/id\/115734122\"">AK-47 | Aquamarine Revenge (Minimal Wear)<\/a>","</a>
<a target="\"_blank\"" href="\"\/id\/115734122\"">23.44<\/a>","</a>
<a target="\"_blank\"" href="\"\/id\/115734122\"">21.85<\/a>","</a>
<a target="\"_blank\"" href="\"https:\/\/track.steamanalyst.com\/730\/115734122\/all\"">17.61<\/a>","</a>
<a target="\"_blank\"" href="\"\/id\/115734122\"">533<\/a>","</a>
<a target="\"_blank\"" href="\"\/id\/115734122\"">-2.65<\/a>","</a>
<a target="\"_blank\"" href="\"\/id\/115734122\"">0.94387<\/a>"],["</a>
</body>
我的代碼:
List<string> Data = new List<string>();
foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//a[@target]"))
{
if(j <= 6)
{
Data.Add(node.InnerText);
if (j == 6)
{
JsonDB.Add(Data[0], Data[1]);
Data.Clear();
j = 0;
}
else
{
j++;
}
}
}
問題與此代碼:node.InnerText顯示所有InnerTexts的接串身體中的所有標籤!基本上,它顯示了這個在doc.DocumentNode.SelectNodes("//a[@target]")
的第一個節點:
AK-47 | Aquamarine Revenge (Factory New)","33.8","34.34","25.89","170",
"-1.27","2.03181"],[...
@Pang這真的不是問題,但更重要的是,它顯示了所有連接字符串作爲一個節點。基本如此:AK-47 |海藍寶石復仇(新工廠版)「,」33.8「,」34.34「,」25.89「.... – Nikolas