這是我試圖提取突出顯示的數據的html文檔c#Html敏捷包獲取div和跨度節點
我在這個網站上閱讀了很多,但無法找到有用的解決方案。 我試過使用
nodes = doc.DocumentNode.SelectNodes(table_title + "/tbody/tr/td");
headers = nodes.Elements("span").Select(d => d.InnerText.Trim());
foreach (var this_header in header)
{
string location = this_header.InnerText.Trim();
Console.Writeline(location);
}
這並沒有給我正確的信息。我如何找到我正在尋找的特定內容?
爲什麼不能在類'today_nowcard-location'選擇或其他地方使用? – juharr
headers = nodes.Elements(「/ h1 [@class ='today_nowcard-location']」)。Select(d => d.InnerText.Trim());像那樣?我得到一個錯誤的對象引用未設置爲對象的實例。 –
你需要用'//'而不是'/'開始你的xpath,因此它會搜索多個深度級別。你也應該可以直接在'doc.DocumentNode'上做,因爲在你的例子中沒有看到任何表格。 – juharr