I have tried to goole solutions for hours...
I'm doing an app for windowsphone, which is used to show public transport details. I need to change values of WhereFrom and WhereTo and click submit in the tinyurl webpage and then scrape the info. If you can recommend any other way to do this, please tell it. I have also tried webclient, httpwebrequest, but their instructions and examples are way too complicated for me.
I'm stuck with the error mentioned before and the selain.InvokeScript("eval"); line causes it. Even stranger is that I only got this error in this tinyurl website. eg when using www.bing.com site I have another error: 80020101 using the third Invokescript line.
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");
}
}
}
}