C#Webbrowser.invokeScript和错误:80020006仅在此特定站点中 [英] C# Webbrowser.invokeScript and Error: 80020006 only in this particular site

查看:46
本文介绍了C#Webbrowser.invokeScript和错误:80020006仅在此特定站点中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了数小时的解决方案...

I have tried to goole solutions for hours...

我正在为Windows Phone开发一个应用程序,该应用程序用于显示公共交通详细信息.我需要更改WhereFrom和WhereTo的值,然后在tinyurl网页中单击Submit,然后抓取信息.如果您可以推荐其他方法来做到这一点,请告诉它.我也尝试过使用webclient httpwebrequest,但是它们的说明和示例对我来说太复杂了.

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.

我被前面提到的错误和selain.InvokeScript("eval");所困扰.线导致它.甚至更陌生的是,我在这个tinyurl网站上仅收到此错误.例如,当使用www.bing.com网站时,我还有另一个错误:80020101使用了第三条Invokescript行.

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

        }
    }
}

推荐答案

您正在尝试在所有页面中调用名为 eval 的脚本.第二个参数是 eval 函数的自变量.可能是,该页面上没有 eval 功能,因此会出现异常.

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.

在此处InvokeScript上查看文档.

这篇关于C#Webbrowser.invokeScript和错误:80020006仅在此特定站点中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆