I want to use C# to capture a website showing a chart. When the URL is opened, the website will show a "Wait" page first until the data is fully loaded, then it will show the chart. It takes 1 - 3 seconds until the chart is shown properly. We need to capture the chart, not the "Wait" page. Both "Wait" page and the "Chart" page share the same URL.
The problem is that when I use the event:
browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(LoadCompleted);
And check in the LoadCompleted method:
if (browser.ReadyState == WebBrowserReadyState.Complete)
The code inside "if" is executed when the "Wait" page is fully loaded, not the "Chart" page.
I can think of the only solution to wait for several seconds (e.g., 5s) until the chart is fully loaded. I tried to use "Thread.Sleep" at the beginning of method LoadCompleted, but it doesn't work. It seems to pause the main thread and the browser does not continue loading the chart page during the sleep time. Can you please suggest me a way to wait for 5 seconds before capturing the webpage?
Thanks.
Aucun commentaire:
Enregistrer un commentaire