LoginSignup
7

More than 5 years have passed since last update.

ChromeのcookieをPhantomJSにロードして使う

Last updated at Posted at 2016-11-20

ChromeのCookie情報を Chrome Extension の EditThisCookie を使って抽出します。

var cookies = ここにエクスポートを貼り付け;

cookies.forEach(function(cookie) {
  phantom.addCookie({
    'name':     cookie.name,
    'value':    cookie.value,
    'domain':   cookie.domain,
    'path':     cookie.path,
    'httponly': cookie.httpOnly,
    'secure':   cookie.secure,
    'expires':  Math.floor(cookie.expirationDate * 1000)
  });
});

setTimeout(function() {
  phantom.exit();
}, 2000);

上記を load_cookie.js として保存する。

$ phantomjs --cookies-file=saved_cookie.txt load_cookie.js

として実行すると saved_cookie.txt に保存できるので、目的のテスト等においてこの cookie データを流用することができます。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7