我使用WebBrowser从一些网页中删除数据,该网页的javascript加载时间为5-8秒。 (wb.ReadyState!= WebBrowserReadyState.Complete)永远不会发生。怎么会这样?
public static String data { get; set; }
[STAThread]
static void Main(string[] args)
{
string pathToWrite = @"C:\ABC.csv";
string nodelist = @"C:\WebPagelist.txt"; //{"001", "abc.com/mvc/001" /r/n "002", "abc.com/mvc/002" /r/n "003", "abc.com/mvc/003" /r/n ... "499", "abc.com/mvc/499"}
string line;
using (StreamReader reader = new StreamReader(nodelist, Encoding.UTF8))
{
while ((line = reader.ReadLine()) != null)
{
string[] node = line.Split('\t');
Download(node[0], node[1]);
}
}
using (var PlayerFile = new StreamWriter(pathToWrite, true))
{
PlayerFile.Write(data);
PlayerFile.Flush();
}
}
static void Download(string cityName, string url)
{
WebBrowser wb = new WebBrowser();
wb.ScriptErrorsSuppressed = true;
wb.Navigate(url);
while (wb.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
string A = wb.Document.GetElementById("cur_A").InnerText;
string B = wb.Document.GetElementById("cur_B").InnerText;
string C = wb.Document.GetElementById("cur_C").InnerText;
data += A + "," + B +"," + C + + Environment.NewLine;
}