awesomium控制不访问谷歌

Mat*_*ght 2 c# document-ready awesomium

Hy all,

我正在一个类中使用awesomium webcontrol创建一个Winform项目.我正在将该控件导航到http://www.google.com/(仅用于测试)并DocumentReady为其添加了一个偶数列表器.但它不会激发听众......(i don't get the "in the listener!" message)

这是我得到的代码(我称之为doSomeScrap主要形式(Form1):

class scrapper
{
    WebControl web = new WebControl();

    public void doSomeScrap()
    {
        MessageBox.Show("in the scrapper...");
        web.DocumentReady += webcontrolEventListener;
        web.Source = "http://www.google.com".ToUri();
        web.Update();
    }

    private void webcontrolEventListener(object sender, EventArgs e)
    {
        MessageBox.Show("in the listener!");
    }
}
Run Code Online (Sandbox Code Playgroud)

另外,我听说过LoadingFrameCompleted,但是当我使用它时,我收到以下错误:

'Awesomium.Windows.Forms.WebControl' does not contain a definition for 'LoadingFrameCompleted' and no extension method 'LoadingFrameCompleted' accepting a first argument of type 'Awesomium.Windows.Forms.WebControl' could be found (are you missing a using directive or an assembly reference?)
Run Code Online (Sandbox Code Playgroud)

那我做错了什么?或者我忘记了这项工作是什么?

额外的信息: 我有一个gui形式的另一个webcontrol,当我在它上面使用这个代码时(没有update()调用,控件正在导航......所以我的家伙是因为它不在,所以它不会导航GUI.但是我怎么能让它导航呢?

Ste*_*sen 8

如果您不需要向用户显示正在抓取的页面,我将使用可在后台线程上执行的非窗口WebView执行Web抓取.

在非窗口控制台应用程序中进行抓取的示例

// Credit: Awesomium v1.7.2 C# Basic Sample
//         by Perikles C. Stephanidis
using System;
using Awesomium.Core;
using System.Threading;
using System.Diagnostics;
using System.Reflection;

namespace BasicSample
{
    class Program
    {
        static void Main( string[] args )
        {
            WebCore.Initialize(WebConfig.Default);

            Uri url = new Uri("http://www.google.com");

            using ( WebSession session = WebCore.CreateWebSession(WebPreferences.Default) )
            {
                // WebView implements IDisposable. Here we demonstrate
                // wrapping it in a using statement.
                using ( WebView view = WebCore.CreateWebView( 1100, 600, session ) )
                {
                    bool finishedLoading = false;
                    bool finishedResizing = false;

                    Console.WriteLine( String.Format( "Loading: {0} ...", url ) );

                    // Load a URL.
                    view.Source = url;

                    // This event is fired when a frame in the
                    // page finished loading.
                    view.LoadingFrameComplete += ( s, e ) =>
                    {
                        Console.WriteLine( String.Format( "Frame Loaded: {0}", e.FrameId ) );

                        // The main frame usually finishes loading last for a given page load.
                        if ( e.IsMainFrame )
                            finishedLoading = true;
                    };

                    while ( !finishedLoading )
                    {
                        Thread.Sleep( 100 );
                        // A Console application does not have a synchronization
                        // context, thus auto-update won't be enabled on WebCore.
                        // We need to manually call Update here.
                        WebCore.Update();
                    }

                    // Print some more information.
                    Console.WriteLine( String.Format( "Page Title: {0}", view.Title ) );
                    Console.WriteLine( String.Format( "Loaded URL: {0}", view.Source ) );
                } // Destroy and dispose the view.
            } // Release and dispose the session.            

            // Shut down Awesomium before exiting.
            WebCore.Shutdown();

            Console.WriteLine("Press any key to exit...");
            Console.Read();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

使用窗口控制的工作刮刀的示例

using System;
using System.Windows.Forms;

namespace App
{
    public partial class DemoForm : Form
    {
        private Awesomium.Windows.Forms.WebControl web;

        public DemoForm()
        {
            InitializeComponent();
            doSomeScrap();
        }

        public void doSomeScrap()
        {
            MessageBox.Show("in the scrapper...");
            web.DocumentReady += webcontrolEventListener;
            web.Source = new Uri("http://www.google.com");
            web.Update();
        }

        private void webcontrolEventListener(object sender, EventArgs e)
        {
            MessageBox.Show("in the listener!");
        }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            this.web = new Awesomium.Windows.Forms.WebControl();
            this.web.Dock = System.Windows.Forms.DockStyle.Fill;
            this.Controls.Add(this.web);

            this.ClientSize = new System.Drawing.Size(800, 600);
            this.Name = "DemoForm";
            this.Text = "DemoForm";

            this.ResumeLayout(false);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)