私は何時間もソリューションをグールしようとしました...
公共交通機関の詳細を表示するために使用される windowsphone 用のアプリを作成しています。WhereFrom と WhereTo の値を変更し、tinyurl Web ページで [送信] をクリックしてから、情報を取得する必要があります。これを行う他の方法をお勧めできる場合は、それを教えてください。webclient や httpwebrequest も試しましたが、その手順と例は私には複雑すぎます。
前に述べたエラーと selain.InvokeScript("eval"); で立ち往生しています。ラインが原因です。さらに奇妙なのは、この tinyurl Web サイトでのみこのエラーが発生したことです。たとえば、www.bing.com サイトを使用しているときに、3 行目の Invokescript 行で 80020101 という別のエラーが発生しました。
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");
}
}
}
}