1
d0m2o08 2023-10-19 07:44:56 +08:00 1
|
2
ShineyWang 2023-10-19 08:58:58 +08:00
|
3
rukeypei 2023-10-19 09:17:57 +08:00
写一个 chrome extension 直接抓
|
4
DeeCheung 2023-10-19 09:21:27 +08:00
我自己用 `Bun(自带 sqlite) + js` 解析提取,一个 Bun 二进制+脚本即可,你也可以打包在一起单文件当 cli 用,缺点不支持 win
``` js // TODO v11 v12 import { Database } from 'bun:sqlite' import { createDecipheriv, pbkdf2Sync } from 'node:crypto' const KEY_LENGTH = 16 const SALT = 'saltysalt' const IV = Buffer.alloc(KEY_LENGTH).fill(' ') const password = 'peanuts' const key = getDerivedKey(password, 1) function getDerivedKey(password, iterations) { return pbkdf2Sync(password, SALT, iterations, KEY_LENGTH, 'sha1') } function decryptorCookie(encryptedCookie) { const decipher = createDecipheriv('AES-128-CBC', key, IV) const decryptedCookie = decipher.update(encryptedCookie.slice(3)) return decryptedCookie.toString() + decipher.final('utf8') } function parseExpiresUtc(n) { return new Date(n / 1e3 - 116444736e5) } function parseCookie(item) { const { name, host_key, encrypted_value: str, expires_utc, has_expires } = item // V10 const val = decryptorCookie(str) const expires = parseExpiresUtc(expires_utc) const unixTime = +(expires / 1e3).toFixed(0) const out = { key: name, val, has_expires, expires, host: host_key, unixTime } return out } const DefaultDbPath = '~/.config/chromium/Default/Cookies' export function getCookies(sql, dbPath = DefaultDbPath) { const db = new Database(dbPath) const query = db.query(sql) const items = query.all() return items.map(parseCookie) } export function toNetscapeCookieFile(arr) { const lines = arr .map(c => { return `${c.host} TRUE / TRUE ${c.unixTime} ${c.key} ${c.val}` }) .join('\n') return `# Netscape HTTP Cookie File # This file is generated by yt-dlp. Do not edit. ${lines}` } export function toHeadersCookie(arr) { return arr.map(c => `${c.key}=${c.val}`).join('; ') } if (import.meta.main) { const sql = `SELECT * FROM cookies where host_key = '.aliyundrive.com' and name = 'cookie2';` console.log(getCookies(sql)) const sql1 = `SELECT * FROM cookies where host_key = '.bilibili.com' and name = 'SESSDATA';` const cookies = await getCookies(sql) console.log(toNetscapeCookieFile(cookies)) } ``` |
5
DeeCheung 2023-10-19 09:22:58 +08:00
|
6
ayfun 2023-10-19 09:33:29 +08:00
原生 IndexedDB
|
7
yh7gdiaYW 2023-10-19 09:45:34 +08:00
一般来说这种应该用 playwright/puppeteer ?不过需求比较简单的话可能重了点
|
8
iOCZ 2023-10-19 10:10:55 +08:00
以前有个人用 go 写的 LeetCode 助手,使用了浏览器里的登录信息,用的一个三方去读取的
|
9
julyclyde 2023-10-19 12:43:40 +08:00
我昨天刚实习了把 cookie 从浏览器抄到 requests 库
先建立一个 SimpleCookie class 的对象,用 SimpleCookie 实例的 load 方法把 cookie 字符串加载进来 再把这个对象压平成文本格式的 dict 用 requests 的 session 对象的 cookie 成员对象的 update 方法读前述 dict 即可 |
10
hollc 2023-10-19 13:38:59 +08:00
如果是因为 2FA 导致程序没法自动登录的话,有 python 实现的 2FA ,可以接入进去
|
11
Cooooooode 2023-10-19 13:53:23 +08:00
playwright 吧
|
12
Qetesh 2023-10-19 22:10:10 +08:00
使用 selenium 模拟登录,2FA 在模拟登录也好解决。可以很方便取到最新 cookie
|