我试图古尔解决方案小时...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