webBroser获取cookie

//取当前webBrowser登录后的Cookie值
        [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
        static extern bool InternetGetCookieEx(string pchURL, string pchCookieName, StringBuilder pchCookieData, ref int pcchCookieData, int dwFlags, object lpReserved);
        //取出Cookie,当登录后才能取
        private static string GetCookieString(string url)
        {
            // Determine the size of the cookie
            int datasize = 256;
            StringBuilder cookieData = new StringBuilder(datasize);
            if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x00002000, null))
            {
                if (datasize < 0)
                    return null;
                // Allocate stringbuilder large enough to hold the cookie
                cookieData = new StringBuilder(datasize);
                if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x00002000, null))
                    return null;
            }
            return cookieData.ToString();
        }
时间: 2024-12-07 22:50:27

webBroser获取cookie的相关文章

用WebCollector 2.x爬取新浪微博(无需手动获取cookie)

用WebCollector 2.x 配合另一个项目WeiboHelper,就可以直接爬取新浪微博的数据(无需手动获取cookie) 1.导入WebCollector 2.x和WeiboHelper的所有jar包 两个项目的地址:http://git.oschina.net/webcollector/WebCollector http://git.oschina.net/webcollector/WeiboHelper 2.示例代码: package cn.edu.hfut.dmic.webcol

【学习笔记】JavaScript设置与获取Cookie

获取Cookie: 1 function getCookie(cookiename) { 2 var result; 3 var mycookie = document.cookie; 4 var start2 = mycookie.indexOf(cookiename + "="); 5 if (start2 > -1) { 6 start = mycookie.indexOf("=", start2) + 1; 7 var end = mycookie.i

设置cookie、获取cookie、删除cookie函数封装

//设置cookie函数function setCookie(key,value,t){   var oDate = new Date();   oDate.setDate( oDate.getDate() + t );   document.cookie = key + '=' + encodeURI(value) + ';expires=' + oDate.toGMTString();} //获取cookie函数function getCookie(key){ //通过分号空格拆分开所有co

如何使用js来获取cookie的值

如何使用js来获取cookie的值 读取属于当前文档的所有cookies var allcookies = document.cookie; 定义一个函数,用来读取特定的cookie值. function getCookie(cookie_name) { var allcookies = document.cookie; var cookie_pos = allcookies.indexOf(cookie_name);   //索引的长度 // 如果找到了索引,就代表cookie存在, // 反

js获取cookie值

js获取cookie值,代码如下: 1 function getCookie(key) { 2 var arr = document.cookie.split(';'); 3 var obj = new Object(); 4 for(var i = 0; i < arr.length; i++) { 5 var tmp = arr[i].split('='); 6 obj[tmp[0]] = tmp[1]; 7 } 8 return obj[key]; 9 } 调用: 1 alert(getC

javascript设置和获取cookie值

//设置cookie function setCookie(name,value,expires,path,domain,secure){ var cookieName = encodeURIComponent(name) + '=' + encodeURIComponent(value); if(expires instanceof Date){ cookieName += ';expires=' + expires; } if(path){ cookieName += ';path=' +

jQuery获取cookie

之前一直以为获取cookie的方法封装在了jQuery包中...没想到还得单独下jquery.cookie.js插件,不太好找,备份一份: /*! * jQuery Cookie Plugin v1.4.1 * https://github.com/carhartl/jquery-cookie * * Copyright 2013 Klaus Hartl * Released under the MIT license */ (function (factory) { if (typeof de

javascript设置和获取cookie的通用方法

//获取cookie  function getCookieValue(cookieName)  {     var cookieValue = document.cookie;     var cookieStartAt = cookieValue.indexOf(""+cookieName+"=");     if(cookieStartAt==-1)     {         cookieStartAt = cookieValue.indexOf(cooki

PHP获取Cookie模拟登录

一.定义Cookie存储路径 必须使用绝对路径 $cookie_jar = dirname(__FILE__)."/pic.cookie"; //$cookie_file = dirname(__FILE__).'/cookie.txt'; //$cookie_file = tempnam("tmp","cookie"); 二.获取Cookie $url = "http://1.2.3.4/"; $ch = curl_init