我在我的Web應用程序中使用WebBrowser控件。在DocumentCompleted事件上我想在我的字符串中使用DocumentText。我的DocumentCompleted事件就像下面。Web應用程序中的WebBrowser控件C#
void IEBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
string str = IEBrowser.DocumentText;
}
現在的問題是DocumentText,我想我不會在DocumentCompleted事件中得到它。我認爲有一些JavaScript可以在DocumentCompleted事件之後做些事情。所以我改變我的代碼就像這樣。
void IEBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
Thread th = new Thread(new ThreadStart(startthread));
th.Start();
}
public void startthread()
{
//To Wait untill WebBrowser run that javascript
Thread.Sleep(5000);
string str = IEBrowser.DocumentText;
}
現在通過這段代碼,我得到了「指定的轉換無效」。 我該如何等待WebBrowser運行的線程?
在web應用程序中使用web瀏覽控件?嘗試在Web應用程序內刮取一些東西?更好的方法是使用httpwebrequest,甚至是webclient。 – urlreader