C# Webbrowser.invokeScript and Error: 80020006 only in this particular site

天涯浪子 提交于 2019-12-13 00:36:40

问题


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

        }
    }
}

回答1:


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.



来源:https://stackoverflow.com/questions/10200661/c-sharp-webbrowser-invokescript-and-error-80020006-only-in-this-particular-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!