1

Hi guys i want to import cookies to use with the web browser in a Vb program. These cookies are in a text file exported from foirefox using an addon called advanced cookie manager. This is the full text file content for a youtube and google account cookies.

    accounts.google.com FALSE   /   TRUE    0   GALX    6eHg_ah2OcA
accounts.google.com FALSE   /   TRUE    0   GoogleAccountsLocale_session    en
accounts.google.com FALSE   /   TRUE    0   GAPS    1:_Nr1hdAKxmmjavGHMMvU0mmYvqJE8A:Nc1AzVmN-IKZb3oq
accounts.google.com FALSE   /   TRUE    0   LSID    s.DE|s.youtube|talk|youtube:DQAAALoAAADgCb0yghM0OyhoTEOWeKd__922mYyKa3H0yBIs5jGOfSbMfP6C76Ao7YBT3chA3BA4zmqB3w5so99qg0QzJgh4LmocSsTuOc7aAraSsUH0dxfz0lJpoWxYx7f3hXI1HB2XP6YVtlpHZi-VAjsaaRDLanfpMddm73RtUnlu4xSJoNAgF0xJNogs_Of4EPAssrchOowBKcdM1-P-aQMy7rgvo5V5RF1RxTVZ8dyWRdqk8ocqEk09M-dld3fLm7cZB7g
.youtube.com    TRUE    /   FALSE   0   VISITOR_INFO1_LIVE  2S8cjkP9HuI
.youtube.com    TRUE    /   FALSE   0   use_hitbox  d5c5516c3379125f43aa0d495d100d6ddAEAAAAw
.youtube.com    TRUE    /   TRUE    0   SSID    A6maF6dfv-b3voGtv
.youtube.com    TRUE    /   TRUE    0   SAPISID q2lzZ6EO9sD4zfaO/Ag61mffuXQhzbTylQ
.youtube.com    TRUE    /   TRUE    0   HSID    Al2Ze5_OdWHfE-lKA
.youtube.com    TRUE    /   TRUE    0   APISID  dCxiK0RIWXVF4ss9/ADUW4MrNC4wbMNIZo
.youtube.com    TRUE    /   FALSE   0   PREF    f1=50000000&fv=0.0.0
.youtube.com    TRUE    /   FALSE   0   ACTIVITY    1358853848282
.youtube.com    TRUE    /   TRUE    0   demographics    b5b9b36b16b837de11794f76ac5adc24e3QGAAAAZ2VuZGVydAEAAABtdAMAAABhZ2VpHgAAADA=
.youtube.com    TRUE    /   TRUE    0   SID DQAAALkAAABYU1N6s7Wc4ckiyqekON91HZLX2WNwPAtmyu82zizR8ahweELmw13pWScKM0DWZMn3DrGU4L-ycQQpQ2EirWKdJ0zfjdGZh3iZCfYhDZcCfDgAqSmWpbGS8UW0tbkapa7hTyoSlmu342A7xWtzujGSVW94RvmXmKc7f9U6jKQ55rTABiaoiZ3DEYqDjb2pSfGu9x1wRSTpDH09nGT_rvN-IPr6Exy9aLErbk0VHhjeQVD-a93jPbKs_71T9gGmr00
.youtube.com    TRUE    /   TRUE    0   LOGIN_INFO  ad4923957f199d9967473fbb9efc6facc3cAAAB7IjEiOiAxLCAiMiI6ICJSWVh2cXhhMHRMQmZaUHowTEpSdGFRPT0iLCAiMyI6IDEzNjEyNDgyMDYsICI0IjogIkdBSUEiLCAiNiI6IGZhbHNlLCAiNyI6IDEzNTg5NTY1ODAsICI4IjogNTMwMDM1NDIxMzY3fQ==`

All i want to know is :how can i use these text files or its content with the Vb web browser.

4

2 回答 2

6

InternetSetCookie 函数应该仍然有效

http://netpl.blogspot.com/2008/09/property-of-mshtmlihtmldocument2-does.html

您将需要解析您的文件(简单),然后为每个 cookie 调用该方法。WebBrowser 应该获取 cookie,我们在过去多次使用过这种技术。

于 2013-10-07T21:45:20.803 回答
6

我假设您想使用 WinFormsWebBrowser控件。

根据 MSDN,WebBrowser 控件没有Cookies属性,这是因为,我认为,WebBrowser 使用与桌面 IE 相同的浏览器状态......这并不重要。

根据 MSDN 上的这个线程(http://social.msdn.microsoft.com/Forums/windows/en-US/e43239f3-3914-43ec-ac50-223b022ec2ea/webbrowser-control-and-cookies?forum=winformsdesigner)你可以通过从 中导入InternetSetCookie函数来添加 cookie wininet.dll

所以我会做这样的事情(在 C# 中,抱歉,但将其转换为 VB 应该很容易)

// Ideally I'd parse the text-file using a finite-state-machine parser modelled on a CSV parser, but for this exercise I'll resort to `String.Split`.

private static List<String[]> GetCookieLines(String fileName) {

    List<String[]> cookieLines = new List<String[]>();
    using(FileStream fs = new FileStream( pathToYourCookies.txt, FileMode.Open ))
    using(StreamReader rdr = new StreamReader( fs, Encoding.UTF8 )) { 

        String line;
        while( (line = rdr.ReadLine()) != null ) {

            String[] components = line.Split('\t'); // assuming tab-separated file
            cookieLines.Add( components )
        }
    }
}

[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern Boolean InternetSetCookie(string urlName, string cookieName, string cookieData);

public static void ImportCookies(String fileName) {

    List<String[]> cookies = GetCookieLines( fileName );
    foreach(String[] cookie in cookies) {

        String domainName = cookie[0];
        String name       = cookie[4];
        String value      = cookie[5];

        InternetSetCookie( domainName, name, value );
    }
}
于 2013-10-07T21:50:17.277 回答