我試圖古爾解決方案小時...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");
}
}
}
}
我對這個解決方案感到厭倦,並嘗試使用httpwebrequest,httpwebresponse和Html敏捷包來獲得更好的結果:)。 httpwebrequest使用起來稍微麻煩一點,但它起作用。 – onnimonni 2012-04-18 21:25:41