HTMLからテキストを取得するための関数がほとんどないforeachを使用しようとすると。テキストはすべての反復で常に同じですが、ブレークポイントを追加して foreach 変数にあるテキストをチェックすると、テキストが変更されました。コードは次のとおりです。
foreach (HtmlNode nodes in listingNode.ChildNodes)
{
i++;
int row = dataGridView1.Rows.Add();
dataGridView1.Rows[row].Cells[0].Value = i; // ktory z kolei?
HtmlAttributeCollection imageNode = nodes.SelectSingleNode("//div[@class='bmlistt']").Attributes; // image
string node = imageNode[1].Value; // link for that image
// add adding image to row
dataGridView1.Rows[row].Cells[1].Value = null; // image
//HtmlNode artistspan = artistNode.SelectSingleNode("//span[@class='artist']");
dataGridView1.Rows[row].Cells[2].Value = nodes.SelectSingleNode("//div[@class='maintext']").SelectSingleNode("//span[@class='artist']").InnerHtml; //returns always same text
dataGridView1.Rows[row].Cells[3].Value = null; // title
dataGridView1.Rows[row].Cells[4].Value = null; // difficulties
//dataGridView1.Rows[row].Cells[5].Value = null; // Checkbox
if (i == 10)
{
i++; // breakpoint
}
}
ブレークポイントからのローカル (10 回の反復後)
https://dl.dropbox.com/u/21125662/compilation/_01055.jpg
オレンジ色の線は何が問題なのかを示しています。(コードを見てからスクリーンショットを見てください) (ノードは常にノードと同じである必要があります)