Watin HTML源未更新

时间:2013-01-07 16:17:14

标签: c# watin

我正在尝试使用Watin自动化soundclouds API,因为我需要将一系列用户ID转换为用户名。

我在IE中显示json结果正常,浏览器完全按计划循环。

我可以获取html.tostring()并将其写入第一个用户的100%罚款文件。但是当循环继续时,html.tostring()似乎不会更新,只是复制第一个用户数据。 (请记住,实际的浏览器正在循环用户)

IE ie = new IE();


while (counter <= counterMax)
{

    ie.GoTo("http://api.soundcloud.com/users/" + counter + ".json?client_id=YOUR_CLIENT_ID");

    Console.WriteLine(ie.Html.ToString());               
    System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\path\\" + counter + ".txt");          
    file.WriteLine(ie.Html.ToString());
    file.Close();

    counter++;


}


ie.Close();

我无法弄清楚,如果我在循环的每次迭代中关闭并重新打开浏览器,它按计划运行,但这对于我需要使用的数据量来说需要太长时间。

1 个答案:

答案 0 :(得分:0)

试试这个:

System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\path\\" + counter + ".txt", true); 

您需要启用追加,以便每次循环遍历时,流都可以写入文件。