2012-04-17 24 views
1

我試圖古爾解決方案小時...C#Webbrowser.invokeScript和錯誤:80020006只在這個特定的網站

我做了WindowsPhone的,它是用來顯示公交信息的應用程序。 我需要更改WhereFrom和WhereTo的值,然後在tinyurl網頁中單擊提交,然後刮取信息。 如果你能推薦任何其他的方式來做到這一點,請告訴它。我也嘗試過webclient,httpwebrequest,但是他們的指示和例子對我來說太複雜了。

我被前面提到的錯誤和selain.InvokeScript(「eval」);線導致它。更奇怪的是,我在這個tinyurl網站上只有這個錯誤。例如,當使用www.bing.com網站時,我有另一個錯誤:80020101使用第三個Invokescript行。

using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
using Microsoft.Phone.Controls; 
using System.Runtime.InteropServices; //COMException 
namespace PhoneApp5 
{ 

    public partial class MainPage : PhoneApplicationPage 
    { 

     // Constructor 
     public MainPage() 
     { 

      InitializeComponent(); 
      //selain as WebBrowser. It's instanted in mainpage.xaml 

      selain.IsScriptEnabled = true; 

      selain.LoadCompleted += new System.Windows.Navigation.LoadCompletedEventHandler(selain_LoadCompleted); 

      selain.Navigating +=new EventHandler<NavigatingEventArgs>(selain_Navigating); 
      string osoite = "http://tinyurl.com/c7xel8s"; 
      //string osoite = "http://bing.fi"; 
      selain.Navigate(new Uri(osoite)); 

     } 

     private void selain_Navigating(object sender, NavigatingEventArgs e) 
     { 

     } 

     private void selain_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) 
     { 
      //Updates textblock in mainpage 
      tekstiBlokki.Text = "READY"; 
     } 


     private void button1_Click(object sender, RoutedEventArgs e) 
     { 
      try 
      { 
       selain.InvokeScript("eval"); 
       selain.InvokeScript("eval", "document.getElementById('keya')"); 
       selain.InvokeScript("eval", "document.getElementById('sb_form_q').value = 'Roadname';"); 
       //selain.InvokeScript("eval", "document.getElementById('keyb').value=\"" + textBox2.Text + '\"'); 
      } 
      catch (ObjectDisposedException) 
      { 
       MessageBox.Show("Selain ei ole enää toiminnassa"); 
      } 
      catch (InvalidOperationException) 
      { 
       MessageBox.Show("Reference not found"); 
      } 
      catch (COMException) 
      { 
       MessageBox.Show("Vastaavaa Jscript funktiota ei löydy"); 
      } 

     } 
    } 
} 
+0

我對這個解決方案感到厭倦,並嘗試使用httpwebrequest,httpwebresponse和Html敏捷包來獲得更好的結果:)。 httpwebrequest使用起來稍微麻煩一點,但它起作用。 – onnimonni 2012-04-18 21:25:41

回答

-1

您試圖調用一個名爲EVAL中的所有頁面的腳本。第二個參數是參數對於評估函數。很可能,頁面上沒有eval函數可用,因此您會得到一個異常。

查看InvokeScript here的文檔。

+0

但是在桌面瀏覽器中使用這些命令可以在兩個站點上工作... – onnimonni 2012-04-18 07:12:37

+0

eval是瀏覽器中的一種內置功能,應該始終可用。 – Art 2012-06-06 04:29:36

相關問題