Cefsharp 获取源码和cookie

   private async void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e)
        {
            CookieVisitor visitor = new CookieVisitor();
            visitor.SendCookie += visitor_SendCookie;
            ICookieManager cookieManagesr = chromeBrowser.GetCookieManager();
            cookieManagesr.VisitAllCookies(visitor);
            cookieManagers = cookieManagesr;

            //读取网址源码
            var url = e.Url;
            var result = await chromeBrowser.GetSourceAsync();
            var html = result;
        }

   
    private void visitor_SendCookie(CefSharp.Cookie obj)
        {
            //obj.Domain.TrimStart('.') + "^" +
            string cookies = obj.Name + ":" + obj.Value + ";";
        }
        public class CookieVisitor : CefSharp.ICookieVisitor
        {
            public event Action<CefSharp.Cookie> SendCookie;
            public void Dispose()
            {

            }

            public bool Visit(Cookie cookie, int count, int total, ref bool deleteCookie)
            {
                deleteCookie = false;
                if (SendCookie != null)
                {
                    SendCookie(cookie);
                }

                return true;

            }



        }

 

posted @ 2020-08-19 16:52  学竹  阅读(1788)  评论(0编辑  收藏  举报