예제 #1
0
        /// <summary>
        /// 获取cookie
        /// </summary>
        /// <param name="DomainStr">根据域名获取,如果DomainStr为空则获取所有的cookie</param>
        /// <returns></returns>
        public List <CefSharp.Cookie> GetCookieList(string DomainStr = "")
        {
            var visitor = new CookieMonster();

            if (DomainStr.Length > 0)
            {
                var cookieManager = CefSharp.Cef.GetGlobalCookieManager();
                if (cookieManager.VisitAllCookies(visitor))
                {
                    visitor.WaitForAllCookies();
                    return(visitor.cookies.Where(p => p.Domain == DomainStr || p.Domain == "." + DomainStr).ToList());
                }
                else
                {
                    return(visitor.cookies);
                }
            }
            else
            {
                var cookieManager = CefSharp.Cef.GetGlobalCookieManager();
                if (cookieManager.VisitAllCookies(visitor))
                {
                    visitor.WaitForAllCookies();
                }
                return(visitor.cookies);
            }
        }
예제 #2
0
        async void webbrowser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e)
        {
            string _url = e.Url;

            //判断是否是需要获取cookie的页面
            if (_url.Contains(domian))
            {
                //注册获取cookie回调事件

                var visitor = new CookieMonster();
                //var list = visitor.GetCookieList("www.kaoshibao.com");
                var isSucess = visitor.setCookie("www.kaoshibao.com", "ceshi", "123456", true);
            }
        }