2013-08-22 190 views
1

我在谷歌集團提出問題,他們告訴我實施'CefStringVisitor'類,我這樣做。CefGlue如何獲取HTML源代碼?

namespace Xilium.CefGlue.WPF.Customer 
{ 
    class MyCefStringVisitor : CefStringVisitor 
    { 
     private string html; 
     protected override void Visit(string value) 
     { 
      html = value; 
     } 

     public string Html 
     { 
      get { return html; } 
      set { html = value; } 
     } 
    } 
} 

但我收到的是文本詞,而不是HTML soucrce。

如何獲取HTML源代碼?

回答

0

試試這個

private sealed class SourceVisitor : CefStringVisitor 
{ 
    private readonly Action<string> _callback; 

    public SourceVisitor(Action<string> callback) 
    { 
     _callback = callback; 
    } 

    protected override void Visit(string value) 
    { 
     _callback(value); 
    } 
} 


protected override void OnLoadEnd(CefBrowser browser, CefFrame frame, int httpStatusCode) 
{ 
     if (frame.IsMain) 
     { 
      string HtmlSourceCode; 
      var visitor = new SourceVisitor(text => 
      { 
       BeginInvoke(new Action(() => 
        { 
         HtmlSourceCode = text; 
        })); 
      }); 
      frame.GetSource(visitor); 
     } 
}