Giter Site home page Giter Site logo

gcookie's Introduction

gcookie

A tool for getting site cookie from your browser.

Note

Chrome above 110 would lock Cookies file when browser is running. please run gcookie with administrator privileges or close browser.

Edge has a running process in background, please terminate it or elevate gcookie's privileges

About

When you write a script for scraping some data, you may need the cookie of the site. Instead of copying cookie string from Browser, you can use the std output of this tool.

const { execSync } = require('child_process');
let site = 'bing.com';
const cookie = execSync(`gcookie ${site}`).toString();
from subprocess import check_output
site = 'https://cn.bing.com'
# output of cookies in `cn.bing.com`. not `bing.com`
cookie = check_output(['gcookie', '-c', 'Edge', site]).decode("utf-8")
# example in Scrapy
def get_cookies_dict(cookies):
    if not cookies:
        return {}
    return {c.split('=')[0]: c.split('=')[1] for c in cookies.split('; ')}

class DemoSpider(scrapy.Spider):
    name = 'demo'

    def start_requests(self):
        cookies_dict = get_cookies_dict("your_cookies")
        yield scrapy.Request(
            url,
            headers={'Content-Type': 'application/json'},
            cookies=cookies_dict,
            callback=self.parse,
        )

This package bertrandom/chrome-cookies-secure depends on win-dpapi. win-dpapi based on an older version of node-gyp is diffcult to install on Windows.

moonD4rk/HackBrowserData

This tools can export all of the data. In my case, I just want to a single site's cookie.

Supported Browser

Windows

Firefox, Chrome, Edge, Chromium

Linux

Firefox

Install

download the release for your system and run the binary

Usage

Usage: gcookie [OPTIONS] <site>

gcookie -h print help infomation.

Examples

# App would use Chrome's cookie
> gcookie "google.com"
1P_JAR=2022-07-20-12; APISID=xxxyyyyy

# App would use Edge's cookie
> gcookie -c Edge "bing.com"

# App would use Firefox's cookie
> gcookie -f /path/to/profiles/xx.p "bing.com"

# App would use Chrome's cookie in this path
> gcookie -p /path/to/User Data/Default "bing.com"

Lib Usage

Add this to your Cargo.toml

[dependencies]
gcookie = "*"

get cookie by Chrome

let site = "http://cn.bing.com";
let cookie = gcookie::gcookie_chrome(site, None, None);

let site = "bing.com";
let browser = Some("Edge");
let cookie = gcookie::gcookie_chrome(site, browser, None);
assert!(cookie.is_ok());

Development

git clone https://github.com/zhifengle/gcookie

# Build
cd gcookie
cargo build

# Run unit tests and integration tests
cargo test

# Install
cargo install --path .

gcookie's People

Contributors

zhifengle avatar xxnuo avatar

Stargazers

 avatar ZengJie avatar  avatar Arbal avatar acid avatar  avatar  avatar Shane Witbeck avatar Mr.Tang avatar  avatar 仓鼠 avatar Haoyi HAN avatar nnnZhizhi avatar just do it avatar PingLin Li avatar LiYiZhou avatar  avatar Laris Qiao avatar 混子 avatar  avatar InitCool avatar th7 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.