尽管这种情况很脆弱,但在您的情况下还是可以的-基本上只包括所有图像
alt属性的文本内容:
// Iterate all rows in the first tableHtmlNodeCollection rows = tables[0].SelectNodes(".//tr");for (int i = 0; i < rows.Count; ++i){ // Iterate all columns in this row HtmlNodeCollection cols = rows[i].SelectNodes(".//td"); for (int j = 0; j < cols.Count; ++j) { var images = cols[j].SelectNodes("img"); if(images!=null) foreach (var image in images) { if(image.Attributes["alt"]!=null) Console.WriteLine(image.Attributes["alt"].Value); } // Get the value of the column and print it string value = cols[j].InnerText; Console.WriteLine(value); }}


