1

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");
            }

        }
    }
}
Onni Hakala
  • 563
  • 4
  • 18
  • I got tired with this solution and tried httpwebrequest,httpwebresponse and Html agility pack with much better results :). httpwebrequest is slightly more annoying to use but it works. – Onni Hakala Apr 18 '12 at 21:25

1 Answers1

0

You are trying to invoke a script called eval in all pages. The second parameter is the argument for the eval function. Chances are, there is no eval function available on the page, therefore you get an exception.

Review the docs for InvokeScript here.

Den
  • 16,686
  • 4
  • 47
  • 87
  • eval is a built-in function in the browser, it supposed to be always available. – Art Jun 06 '12 at 04:29